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')`
Last active
May 6, 2024 09:45
-
-
Save nasrulhazim/cfd5f01e3b261b09d54f721cc1a7c50d to your computer and use it in GitHub Desktop.
Download Files From FTP Server using Python3
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?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.