我正在尝试使用以下代码获取 FTPS FileZilla 服务器的目录列表:
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()
时出现异常:
the underlying connection was closed. The server committed a protocol violation.
当我切换到正常的 FTP 连接时。一切正常。
我是否遗漏了建立此 FTPS 连接的内容? 谢谢帮助
最佳答案
FtpWebRequest
类不支持
隐式 FTPS(参见 here)。
当 EnableSsl
设置为 true 时,它实际上会向服务器触发一个 AUTH TLS
命令,要求启动一个 Explicit FTPS session 。
在您的情况下,您必须将 Filezilla Server 配置为使用显式 FTPS。该过程记录在 Filezilla Wiki 上
关于c# - 基础连接已关闭。服务器违反了协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26278782/