Seek a buffer to the start
I've been caught out a few times by forgetting this: when you create a StringIO buffer, writing some lines to it, you need to reset the pointer back to the beginning of the buffer. The all important line is in bold. Without this the file will be uploaded with no contents.
import cStringIO from ftplib import FTP def main(): buf = cStringIO.StringIO() buf.write('Hello, \n') buf.write('World!\n') buf.seek(0) try: conn = FTP('ftp.myserver.com') conn.login() print conn.storlines('STOR /tmp/greetings.txt', buf) finally: conn.close()