I had a chance to use ftp with Python, so I'll leave it as a note.
import ftplib
ftp = ftplib.FTP(IP_ADDRESS)
ftp.set_pasv('true')
ftp.login(USER, PASSWORD)
ftp.close ()
at the end of the processwith open("a.txt", "rb") as f:
ftp.storlines("STOR /aa.txt", f)
rb
Must be opened in binary mode (binary)with open("b.txt.zip", "rb") as f:
ftp.storbinary("STOR /bb.zip", f)
with open("b.txt", "w") as f:
ftp.retrlines("RETR /aa.txt", f.write)
with open("b.txt.zip", "wb") as f:
ftp.retrbinary("RETR /bb.zip", f.write)
If you don't use with
, it looks like this
#Binary is rb, text is r
f = open(filename, 'rb')
ftp.storbinary('STOR {}'.format(PATH), f)
f.close ()
ftp.mkd("XXX")
file_list = ftp.nlst(".")
print(file_list)
try:
# process
except ftplib.all_errors as e:
print('FTP Error :', e)
Recommended Posts