nasrulhazim
4/9/2017 - 12:51 AM

Download Files From FTP Server using Python3

Download Files From FTP Server using Python3

from ftplib import FTP
from datetime import datetime

start = datetime.now()
ftp = FTP('your-ftp-domain-or-ip')
ftp.login('your-username','your-password')

# Get All Files
files = ftp.nlst()

# Print out the files
for file in files:
    print("Downloading..." + file)
    ftp.retrbinary("RETR " + file ,open("download/to/your/directory/" + file, 'wb').write)

ftp.close()

end = datetime.now()
diff = end - start
print('All files downloaded for ' + str(diff.seconds) + 's')`