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?