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')`
-
-
Save nasrulhazim/cfd5f01e3b261b09d54f721cc1a7c50d to your computer and use it in GitHub Desktop.
Thank you you did great.
Regards
Saiful
This works fine if the file size is small, but when you try to download larger files using this code, it will fail.
This is cool.
My files are in subdirectories of the ftp I am trying to download, how do I download all directory with the files in them.
I have tried this but am failing at understanding how to indicate the path to the location to put the files. I can see the list of files in variable "files", but I cannot transfer them to my local drive.
In this example I tried to indicate the path:
Print out the files
for file in files:
print("Downloading..." + file)
ftp.retrbinary("RETR " + file ,open("c:\python_work\ftp" + file, 'wb').write)
but I get this error:
OSError: [Errno 22] Invalid argument: 'c:\python_work\x0ctp.'
this is the code for downloading all files, what if i want to download in selected date range?
Thank you! You are awesome.