我正在尝试使用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()抛出异常。以下是快速监视窗口中显示的异常的屏幕截图:
答案 0 :(得分:0)
错误消息让我觉得你的超时时间太短了。尝试设置一个荒谬的长时间超时,看看你是否有任何流量。最糟糕的情况是,使用wireshark并将您的请求与FileZilla的请求进行比较。 VB在手动数据包操作方面并不是最好的,但是通过比较请求数据包可能会在配置中出现问题。
答案 1 :(得分:0)
使用端口990时,不能使用“显式加密模式”。如果需要连接到端口990,请使用Implicit EncryptionMode。