【问题标题】:FTPClient - Timed out trying to read data from the socket streamFTPClient - 尝试从套接字流中读取数据时超时
【发布时间】:2018-01-18 06:21:12
【问题描述】:

我正在尝试使用FTPClient 连接到 vb.net 中的安全 ftp 服务器。我可以通过 filezilla 连接和上传/下载数据。但是从 .net 代码中,我遇到了超时问题。我是否犯了任何错误,或者我的以下代码中是否缺少任何内容?

Public Function ftpDownload(ByVal strFileName As String) As FileStream
        Try
            Dim client As New FtpClient("ftp://xxx.xxx.xxx.xxx")
            client.Port = 990
            client.Credentials = New NetworkCredential("myusername", "mypassword")
            client.EncryptionMode = FtpEncryptionMode.Explicit
            client.DataConnectionEncryption = True
            client.ReadTimeout = 20000
            client.DataConnectionType = FtpDataConnectionType.AutoPassive
            'System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

            client.Connect()

            Dim arr As New MemoryStream()
            client.Download(arr, strFileName)
            Using responseStream As IO.Stream = arr
                Using fs As New IO.FileStream("c:\temp\temp.123", FileMode.Create)
                    Dim buffer(2047) As Byte
                    Dim read As Integer = 0
                    Do
                        read = responseStream.Read(buffer, 0, buffer.Length)
                        fs.Write(buffer, 0, read)
                    Loop Until read = 0
                    responseStream.Close()
                    'fs.Flush()
                    'fs.Close()
                    Return fs
                End Using
                responseStream.Close()
            End Using
        Catch ex As Exception
            MsgBox(ex)
            Return Nothing
        End Try

它从 client.Connect() 抛出异常。以下是在快速观察窗口中看到的异常截图:

【问题讨论】:

标签: vb.net ftp-client ftps


【解决方案1】:

错误消息让我觉得您的超时时间太短了。尝试设置一个非常长的超时时间,看看你是否有任何流量。在最坏的情况下,使用wireshark 并将您的请求与来自FileZilla 的请求进行比较。 VB 在手动数据包处理方面并不是最好的,但您的配置中可能存在一些错误,通过比较请求数据包会发现。

【讨论】:

    【解决方案2】:

    当使用端口 990 时,您不能使用显式加密模式。如果您需要连接到端口 990,请使用 Implicit EncryptionMode。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-27
    • 2020-02-11
    • 1970-01-01
    • 2017-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多