Can I upload an object in memory to FTP using Python?

Posted by fsckin on Stack Overflow See other posts from Stack Overflow or by fsckin
Published on 2010-04-19T21:38:27Z Indexed on 2010/04/19 21:43 UTC
Read the original article Hit count: 116

Filed under:
|
|
|

Here's what I'm doing now:

mysock = urllib.urlopen('http://localhost/image.jpg')
fileToSave = mysock.read()
oFile = open(r"C:\image.jpg",'wb')
oFile.write(fileToSave)
oFile.close
f=file('image.jpg','rb')
ftp.storbinary('STOR '+os.path.basename('image.jpg'),f)
os.remove('image.jpg')

Writing files to disk and then imediately deleting them seems like extra work on the system that should be avoided. Can I upload an object in memory to FTP using Python?

© Stack Overflow or respective owner

Related posts about python

Related posts about objects