Hi,
I have a small FTP class, written in VB.NET 2.0, which keeps polling for a particular file at a remote location, at 2 minute intervals, till it successfully downloads the file, and then it stops.
So far I had been using wget as an external process, and recently I have switched to using the FtpWebRequest class.
Now what i have noticed is that the first attempt always fails, even if the particular file is available on the remote server. The error returned is System.Net.WebException - Request Timed Out.
However, in the next run, after 2 minutes, the process succeeds, with exactly the same parameters.
The relevant part of the code:
Code:
Dim myFtpWebRequest As FtpWebRequest
Dim myFtpWebResponse As FtpWebResponse
Dim myStreamWriter As StreamWriter
Dim strURL As String = ""
strURL = "ftp://" & strFTPURL & strFTPFolder & strFileName
myFtpWebRequest = DirectCast(WebRequest.Create(strURL), FtpWebRequest)
myFtpWebRequest.KeepAlive = False
myFtpWebRequest.Timeout = 20000
myFtpWebRequest.UsePassive = blnUsePassive
myFtpWebRequest.UseBinary = True
myFtpWebRequest.Credentials = New NetworkCredential(strFTPUserName, strFTPPassword)
myFtpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile
myFtpWebResponse = myFtpWebRequest.GetResponse()
Can someone throw some light on this?
Regards
RB