I am using an httpWebRequest in my windows app to download files from a webserver (sURL), to a local folder (fileDestination) as such:
Public Function DownloadFile(ByVal sURL As String, _
ByVal fileDestination As String, _
ByVal WebRequestType As String) As Boolean
Dim URLReq As HttpWebRequest
Dim URLRes As HttpWebResponse
Dim FileStreamer As FileStream
Dim bBuffer(999) As Byte
Dim iBytesRead As Integer
Dim folderDestination As String
Dim sChunks As Stream
Try
FileStreamer = New FileStream(fileDestination, FileMode.Create)
URLReq = WebRequest.Create(sURL)
URLRes = URLReq.GetResponse 'Error occurs here!!
sChunks = URLReq.GetResponse.GetResponseStream
DownloadProgressBar.Value = 0
DownloadProgressBar.Maximum = URLRes.ContentLength
Do
iBytesRead = sChunks.Read(bBuffer, 0, 1000)
FileStreamer.Write(bBuffer, 0, iBytesRead)
Loop Until iBytesRead = 0
sChunks.Close()
FileStreamer.Close()
URLRes.Close()
Return True
Catch ex As Exception
Return False
End Try
End Function
This works fine for the first few files. But then it starts giving the following error on the URLReq.GetResponse
line:
"operation has timed out"
Anyone know what could be causing this?