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()拋出異常。以下是例外的如被看見在快速監視窗口中的截圖: