I been searching on this for a couple of days and havent found an answer yet.
I have trying to download video files from an FTP, my script checks the server, compares the nlist() to a list of already downloaded files parsed from a text file and then creates a new list of files to get and iterates over it downloading each file, disconnecting from the server and reconnecting for the next file (I thought server timeout might be an issue so I quit() the connection after each file download).
This works for the first few files but as soon as I hit a file that takes longer than 5 mins, fitlib just hangs at the end of the transfer (I can see in explorer that the file is the correct size so the download has completed but it doesnt seem to be getting the message and moving on to the next file)
any help will be greatly appreciated, my code is below:
newPath = "Z:\\pathto\\downloads\\"
for f in getFiles:
print("Getting " + f)
for f in getFiles:
fil = f.rstrip()
ext = os.path.splitext(fil)[1]
if ext in validExtensions:
print("Downloading new file: " + fil)
downloadFile(fil, newPath)
here is download.py
from ftplib import FTP
def downloadFile(filename, folder):
myhost = 'host'
myuser = 'user'
passw = 'pass'
#login
ftp = FTP(myhost,myuser,passw)
localfile = open(folder + filename, 'wb')
ftp.retrbinary("RETR " + filename, localfile.write, 1024)
print("Downloaded " + filename)
localfile.close()
ftp.quit()