0

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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
mquickel
  • 380
  • 3
  • 20
  • 1
    If the problem is on the server, there isn't much you can do. – Steve Wellens Feb 04 '13 at 17:33
  • Sometimes the most obvious answer is the best. I tried copying files down using Windows explorer this afternoon and had consistent timeout errors. My thoughts are that this isn't code related at all, but I may have to better handle the error(s). – mquickel Feb 04 '13 at 18:22

1 Answers1

0

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.

Don
  • 1