Recently I was working on a project and wanted to upload a file on FTP using Python.
import ftplib
from ftplib import FTP
File2Send = ‘file path’
#To upload file in root directory of FTP location
Output_Directory = “”
ftp = FTP(“ftp.ourpcgeek.com”)
http://ftp.login(‘user’,’password’)
file = open(File2Send, “rb”)
http://ftp.cwd(Output_Directory)
http://ftp.storbinary(‘STOR ‘ + File2Send, file)
print (“STORing File now…”)
http://ftp.quit()
file.close()
print(“Processign end”)
Following is the code snippet which you can use in case you want to upload file on FTP using Python script:
import ftplib
from ftplib import FTP
File2Send = ‘C:\\Users\\shamshul\\Pictures\\Saved Pictures\\test1.txt’
Output_Directory = “/upload”
ftp = FTP(“ftp.ourpcgeek.com”)
ftp.login(‘shamshul’,’wfv2l2Fd’)
file = open(File2Send, “rb”)
ftp.cwd(Output_Directory)
ftp.storbinary(‘STOR ‘ + File2Send, file)
print (“STORing File now…”)
ftp.quit()
file.close()
Leave a comment
[wpqa_login]