3

I get the following exception when calling out to a third party FTP server

System.Net.WebException The operation has timed out. - at System.Net.FtpWebRequest.GetResponse()

We have asked the third party what are they doing that cause this and they have said "FTP server was unavailable at the firewall level"

The following is our code:

var _request = (FtpWebRequest)WebRequest.Create(configuration.Url);
_request.Method = WebRequestMethods.Ftp.DownloadFile;
_request.KeepAlive = false;
_request.Timeout = configuration.RequestTimeoutInMilliseconds;
_request.Proxy = null;  // Do NOT use a proxy
_request.Credentials = new NetworkCredential(configuration.UserName, configuration.Password);

_request.ServicePoint.ConnectionLeaseTimeout = configuration.RequestTimeoutInMilliseconds;
_request.ServicePoint.MaxIdleTime = configuration.RequestTimeoutInMilliseconds;

try
{
    using (var _response = (FtpWebResponse)_request.GetResponse())
    using (var _responseStream = _response.GetResponseStream())
    using (var _streamReader = new StreamReader(_responseStream))
    {
        this.c_rateSourceData = _streamReader.ReadToEnd();
    }
}
catch (Exception genericException)
{
    throw genericException;
}
finally
{
   _request.Abort();
}

Our application is a windows service and all resources are getting disposed and even the FtpWebRequest is aborted.

We are calling out to third party every hour and as they do maintenance work and make "FTP server was unavailable at the firewall level" we can no longer call out. we get timeout exception. This occurs even when third party service is available again.

Only solution is to restart windows service to be able to call out again successfully.

Any ideas on this?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Noel
  • 5,037
  • 9
  • 46
  • 69

0 Answers0