Win 7,VS2013,.NET 4.5,winforms app
我尝试使用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和服务点之间缺乏关联。有谁知道如何修理它?我很欣赏某些指示或代码示例。