0

如何检查 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
4

1 回答 1

1

您通常可以设置超时值,如果在上述时间内没有响应,则会抛出WebException ,状态属性为 Timeout。您可以捕获它并适当地处理它。

  Try
    //your code for request/response
  Catch ex As WebException
    MsgBox("Exception reason "&ex.State)
  End Try
于 2012-11-03T17:45:42.353 回答