tags:

views:

38

answers:

1

Hello folks,

I'm having a problem that's been bugging me for a while.

I'm downloading files from a FTP server in .net, and randomly (and I insist, it is completely random), I get the following error:

System.Net.WebException: The remote server returned an error: (550) File unavailable (e.g., file not found, no access).

Our code in .net implements a retry mecanism, so when this error happens, the code will to download all the files again. Then, sometimes, it will succeed, other times, the 550 error will happen on another file, sometimes on the same file, it is completely random.

We is a snippet of the DownloadFile method that is called for each files to be downloaded

byte[] byWork = new byte[2047];
...
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(_uri.ToString() + "/" + filename));
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(_Username, _Password);
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
            {
                using (Stream rs = response.GetResponseStream())
                {
                    using (FileStream fs = new FileStream(destination, FileMode.Create))
                    {
                        do
                        {
                            iWork = rs.Read(byWork, 0, byWork.Length);
                            fs.Write(byWork, 0, iWork);
                        } while (iWork != 0);
                        fs.Flush();
                    }
                }
            }

again, the thing that bugs me is that if there is an error in this code, the 550 error would happen everytime. However, we can try to download a file, we get the error, we try to download the same file with the same parameters again, and it will work. And it seams to happen more frequently with larger files. Any idea?

A: 

Please note, the below is just anecdotal, I don't have anything except vague memories and assumptions to back it up. So rather than a real solution, just take it as a "cheer up, it might not be your fault at all".

I think 550 errors are more likely to be due to some issue with the server rather than the client. I remember getting 550 errors quite often when using an old ISP's badly maintained ftp server, and I did try various clients without it making any real difference. I also remember seeing other people posting messages about similar problems for the same and other servers.

I think the best way to handle it is to just retry the download automatically and hopefully after a few tries you'll get it, though obviously this means that you waste bandwidth.

ho1