如何检查FtpWebRequest超时
Try
Dim request As FtpWebRequest = CType(WebRequest.Create("ftp://"), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails
request.Timeout = 4000
' If 'TimeOut' = False Then
request.Credentials = New NetworkCredential("u", "p")
Using response As FtpWebResponse = CType(request.GetResponse(), FtpWebResponse)
Using responseStream As Stream = response.GetResponseStream()
Using reader As New StreamReader(responseStream)
'do this
End Using
End Using
End Using
'End If
Catch ex As Exception
End Try
答案 0 :(得分:1)
您通常可以设置超时值,如果上述时间没有响应,则WebException将status属性作为Timeout抛出。您可以捕获并正确处理它。< / p>
Try
//your code for request/response
Catch ex As WebException
MsgBox("Exception reason "&ex.State)
End Try