1
FTPClientを使用してvb.netのセキュリティ保護されたftpサーバーに接続しようとしています。私は接続することができてアップロード/ダウンロードファイルを介してデータを。しかし、.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()から例外がスローされています。以下のクイックウォッチウィンドウに見られるような例外のスクリーンショットです: