Skip to content Skip to sidebar Skip to footer

Downloading Second File From Ftp Fails

I want to download multiple files from FTP in python. the my code works when I just download 1 file, but not works for more than one! import urllib urllib.urlretrieve('ftp://ftp.nc

Solution 1:

It is a bug in urllib in python 2.7. Reported here. The reason behind the same is explained here

Now, when a user tries to download the same file or another file from same directory, the key (host, port, dirs) remains the same so open_ftp() skips ftp initialization. Because of this skipping, previous FTP connection is reused and when new commands are sent to the server, server first sends the previous ACK. This causes a domino effect and each response gets delayed by one and we get an exception from parse227()

A possible solution is to clear the cache that may have been built up by previous calls. You may use the urllib.urlcleanup() method calls between your urlretrieve calls for the same, as mentioned here.

Hope this helps!

Post a Comment for "Downloading Second File From Ftp Fails"