0

Win 7、VS2013、.NET 4.5、winforms 应用程序

我正在尝试使用 vb.net 通过 SSL/TLS 连接到 FTP 服务器。我在验证服务器证书时遇到问题,因为我正在使用的 ServerCertificateValidationCallback 方法似乎被忽略了,因此与服务器的连接永远不会发生,在 GetResponse 行出现超时错误。在将服务器证书添加为受信任后,我检查了 FileZilla 上的连接并且它工作正常。

下面是我的 FtpWebRequest:

ServicePointManager.ServerCertificateValidationCallback = Function(obj as [object], _
cert as X509Certificate, chain as X509Chain, error as SslPolicyErrors) _
(cert.Issuer.Equals("xxxxxx"))

Dim req As System.Net.FtpWebRequest = DirectCast(WebRequest.Create(New Uri("ftp://xxx.xxx.xxx:990")), _
System.Net.FtpWebRequest)

req.EnableSsl = True
req.Credentials = New Net.Credential("user","passw")
req.UsePassive = True
req.UseBinary = True
req.Proxy = Nothing
req.Method = WebRequestMethods.Ftp.ListDirectoryDetails

Dim res As System.Net.FtpWebResponse = DirectCast(req.GetResponse(),System.Net.FtpWebResponse)

考虑到 HttpWebRequests,我已经看到类似的主题,但是这里似乎没有什么可用的。我还启用了跟踪以查看详细情况:

System.Net Information: 0 : [17056] Current OS installation type is 'Client'. 
System.Net Verbose: 0 : [17056] WebRequest::Create(ftp://xxx.xxx.xxx:990/)
System.Net Information: 0 : [17056] 
FtpWebRequest#::.ctor(ftp://xxx.xxx.xxx:990/)
System.Net Verbose: 0 : [17056] Exiting WebRequest::Create()    -> 
FtpWebRequest#
System.Net Verbose: 0 : [17056] 
ServicePoint#::ServicePoint(xxx.xxx.xxx:990)
System.Net Verbose: 0 : [17056] FtpWebRequest#::GetResponse()
System.Net Information: 0 : [17056] 
FtpWebRequest#::GetResponse(Method=LIST.)
System.Net.Sockets Verbose: 0 : [17056] 
Socket#::Socket(AddressFamily#2)
System.Net.Sockets Verbose: 0 : [17056] Exiting Socket#::Socket() 
System.Net.Sockets Verbose: 0 : [17056] 
Socket#::Socket(AddressFamily#23)
System.Net.Sockets Verbose: 0 : [17056] Exiting Socket#6::Socket() 
System.Net.Sockets Verbose: 0 : [17056] DNS::TryInternalResolve(xxx.xxx.xxx)
System.Net.Sockets Verbose: 0 : [17056] 
Socket#::Connect(xxx.xxx.xxx:990#-1234)
System.Net.Sockets Information: 0 : [17056] Socket# - Created 
connection from xxx to xxx.xxx.xxx:990.
System.Net.Sockets Verbose: 0 : [17056] Exiting Socket#::Connect() 
System.Net.Sockets Verbose: 0 : [17056] Socket#::Close()
System.Net.Sockets Verbose: 0 : [17056] Socket#::Dispose()
System.Net.Sockets Verbose: 0 : [17056] Exiting Socket#::Close() 
System.Net Information: 0 : [17056] FtpControlStream# - Created 
connection from xxx to xxx.xxx.xxx:990.
System.Net Information: 0 : [17056] Associating FtpWebRequest# with 
FtpControlStream#
System.Net.Sockets Verbose: 0 : [17056] Socket#::Receive()
The thread 0x4ff0 has exited with code 0 (0x0).
System.Net Information: 0 : [0920] ServicePoint# - Closed as idle.
System.Net.Sockets Error: 0 : [17056] 
Socket#::UpdateStatusAfterSocketError() - TimedOut
System.Net.Sockets Error: 0 : [17056] Exception in Socket#::Receive 
- A connection attempt failed because the connected party did not properly 
respond after a period of time, or established connection failed because 
connected host has failed to respond.
System.Net.Sockets Verbose: 0 : [17056] Exiting Socket#::Receive()  
-> Int32#0
System.Net.Sockets Verbose: 0 : [17056] Socket#::Dispose()
System.Net Information: 0 : [17056] FtpWebRequest#::(Releasing FTP 
connection#)
System.Net Error: 0 : [17056] Exception in 
FtpWebRequest#::GetResponse - The operation has timed out..
at System.Net.FtpWebRequest.GetResponse()
A first chance exception of type 'System.Net.WebException' occurred in 
System.dll
System.Net Verbose: 0 : [17056] Exiting 
FtpWebRequest#::GetResponse() 

我看到 FtpWebRequest 和服务点之间缺乏关联。有谁知道如何修理它?我会很感激一些指导或代码示例。

4

0 回答 0