2017-08-10 95 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並不是手動數據包操作的最佳選擇,但是通過比較請求數據包,您的配置中可能會出現錯誤。

相關問題