I'm trying to download a file from a FTP site that uses Passive Mode. I've tried both the FtpWebRequest methods and the WebClient.DownloadFile and DownloadFileAsync methods.
Most recently, my code looks like:
using (var client = new WebClient())
{
client.Proxy = new WebProxy();
client.Credentials = credentials;
client.DownloadFileCompleted += client_DownloadFileCompleted;
client.DownloadFileAsync(new Uri(remotePath), localPath);
}
and is wrapped in a method DownloadFile. In the async handler I get the next item and (recursively) make a call to DownloadFile method again, and so on and so on until I get to the last item.
Almost every single time, every method I use, I get through 6 files and the 7th errors out. Only one time did it get through all of the files in the list and I could not replicate it again. The file counts are about 100 and file sizes are about 30 - 120k a piece. Strangely enough, often I will see the file count in my local folder hang on the 7th item, but if I let the Worker Process run in the background and then come back a few minutes later and shut down IIS express or the VS Web Server, the files will show up. It's too unpredictable, though, and cannot be used in production as is.
I also tried the FTP LIB library on CodePlex and had the same problem.
It seems like something on their end is closing my connection out.
I have had a similar problem. In my case I needed to download many small files from many folders on a Linux server. Sys-admin bloke suggested I put in a 3 second delay between each batch. It greatly reduced the number of errors.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.