I'm writing a function to load files into a specific folder of an FTP area, I get an error on "storbinary" line. PS: "Filename" is a global variable
import ftplib from ftplib import FTP
host = "ftp.test.com"
username = "usr"
password = "pwd"
# connect to ftp
ftp = FTP(host=host, user=username, passwd=password)
# set upload directory
ftp.cwd('Test')
# upload file
with open(os.path.join('/root/ftp/output/', Filename), 'w') as fp:
ftp.storbinary('STOR %s' % os.path.basename(Filename), fp, 1024)
error message: ftp.storbinary('STOR %s' % os.path.basename(Filename), fp, 1024) File "/usr/lib/python3.7/ftplib.py", line 506, in storbinary buf = fp.read(blocksize)
host = "ftp.test.com"
username = "urs"
password = "pwd"
# FTP connection
ftp = FTP(host=host, user=username, passwd=password)
# change upload directory
ftp.cwd('test')
# upload file
upload_file = os.path.join('/root/test/ftp/', Filename)
with open(upload_file, 'rb') as fp:
ftp.storbinary('STOR %s' % os.path.basename(upload_file), fp)
fp.close()
# print the content of directory
print(ftp.dir())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.