ActiveState Code

Recipe 576525: Basic FTP with Python


Sending files to a web server via FTP.

Python
1
2
3
4
5
6
import ftplib                                          
session = ftplib.FTP('SERVER NAME','USERNAME','PASSWORD') 
myfile = open('YOUR FILE','rb')                        
session.storbinary('STOR YOUR FILE', myfile)           
myfile.close()                                         
session.quit()                                         

Discussion

How to use: Replace SERVER NAME with the server name you would like to connect to. Replace USERNAME with your FTP login for that server. Replace PASSWORD with the password that corresponds to your FTP account. Replace YOUR FILE (There are 2 of them) with the file you would like to send.

As far as it goes, I am pretty sure this works. If it doesn't please tell me and I'll fix it.

Sign in to comment