2017-08-10 97 views
1

我试图使用FTPClient连接到vb.net中的安全ftp服务器。我可以通过filezilla连接并上传/下载数据。但是.net代码,我有超时问题。我犯了什么错误,还是在我的下面的代码中有什么遗漏?FTPClient - 尝试从套接字流中读取数据超时

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()抛出异常。以下是例外的如被看见在快速监视窗口中的截图:

enter image description here

回答

0

错误消息使得它看起来对我来说,你的超时太低。尝试设置一个可笑的漫长的超时时间,并看看你是否有任何流量。最糟糕的情况下,使用wireshark并将您的请求与FileZilla中的请求进行比较。 VB并不是手动数据包操作的最佳选择,但是通过比较请求数据包,您的配置中可能会出现错误。

相关问题