问题描述
我正在尝试使用以下代码获取 FTPS FileZilla 服务器的目录列表:
I am trying to get the directory list of a FTPS FileZilla server using the code below :
ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + directory);
ftpRequest.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateCertificate);
ftpRequest.Credentials = new NetworkCredential(user, pass);
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = true;
ftpRequest.KeepAlive = true;
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
在执行 FtpWebResponse)ftpRequest.GetResponse()
时出现异常:
I got an exception when FtpWebResponse)ftpRequest.GetResponse()
is executed :
底层连接已关闭.服务器提交了一个协议违规.
当我切换到普通的 FTP 连接时.一切正常.
When I switch to normal FTP connection. Everything works correctly.
我是否错过了建立此 FTPS 连接的操作?感谢帮助
Did I miss something to establish this FTPS connection ?thanks for help
推荐答案
Implicit FTPS FtpWebRequest
类不支持(请参阅此处).
Implicit FTPS is not supported by the FtpWebRequest
class (see here).
当 EnableSsl
设置为 true 时,它实际上会向服务器触发一个 AUTH TLS
命令,要求启动一个 Explicit FTPS 会话.
When EnableSsl
is set to true, it actually triggers an AUTH TLS
command to the server, asking to start an Explicit FTPS session.
在您的情况下,您必须将 Filezilla 服务器配置为使用显式 FTPS.该过程记录在 Filezilla Wiki
In your case, you have to configure Filezilla Server to use Explicit FTPS. The procedure is documented on Filezilla Wiki
这篇关于基础连接已关闭.服务器违反了协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!