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?
# Open the file for writing in binary mode
print 'Opening local file ' + filename
file = open(filename, 'wb')
# Download the file a chunk at a time
# Each chunk is sent to handleDownload
# We append the chunk to the file and then print a '.' for progress
# RETR is an FTP command
print 'Getting ' + filename
ftp.retrbinary('RETR ' + filename, handleDownload)
# Clean up time
print 'Closing file ' + filename
file.close()
This is a Python code that is working fine for me. Comments are in Spanish but the app is easy to understand
The
ftplib
module in the Python standard library can be compared to assembler. Use a high level library like: https://pypi.python.org/pypi/ftputilPlease note if you are downloading from the FTP to your local, you will need to use the following:
Otherwise, the script will at your local file storage rather than the FTP.
Spend a few hours making the mistake myself.
Script below:
Of course it would we be wise to handle possible errors.