|Save a file to FTP with Python|
If you want to save a text file with Python to a FTP server, you could use this:
from ftplib import FTP ftp = FTP("myhost.com") ftp.login("username", "password") # open the file to read it as a file like object f = open("myfile.txt", "r") # Open directory ftp.cwd("/pub/cms/textfiles") # save file like object as to the ftp path /pub/cms/textfiles ftp.storlines("STOR myfile.txt", f) ftp.quit() f.close()
If it is a binary file, you should take ftp.storbinary() with the same arguments.
|Last Updated ( Sunday, 25 May 2008 )|
|< Prev||Next >|
Hint: For syntax highlighting and correct Python intendation place your code between html tags <pre> and </pre>.