I have the following code which easily connects to the FTP server and opens a zip file. I want to download that file into the local system. How to do that?
#
Please note if you are downloading from the FTP to your local, you will need to use the following:
with open( filename, 'wb' ) as file :
ftp.retrbinary('RETR %s' % filename, file.write)
Otherwise, the script will at your local file storage rather than the FTP.
I spent a few hours making the mistake myself.
Script below:
import ftplib
# Open the FTP connection
ftp = ftplib.FTP()
ftp.cwd('/where/files-are/located')
filenames = ftp.nlst()
for filename in filenames:
with open( filename, 'wb' ) as file :
ftp.retrbinary('RETR %s' % filename, file.write)
file.close()
ftp.quit()