c# - 基础连接已关闭。服务器违反了协议(protocol)

标签 c# ssl ftpwebrequest filezilla ftps

我正在尝试使用以下代码获取 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/

相关文章:

ios - 使用 Alamofire 将 iOS 应用程序连接到本地主机上运行的 api 时,证书无效

c# - 从 FTP 上传文件和下载文件

c# - 使用 FtpWebRequest 上传期间 "Requested URI is invalid"

c# - 全文搜索jquery-高亮黄色背景

c# - 如何编写加载项以在 Visual Studio 编辑器中更改文本颜色?

c# - WCF 事件顺序

c# - 如何在 C# 中发送任意 FTP 命令

c# - 在具有不同大小写的 switch-case block 中比较 C# 中的字符串

ssl - Jenkins 在测试电子邮件通知时抛出 "java.io.EOFException: SSL peer shut down incorrectly"

客户端首选项 [TLS12] 不接受 Java (javaws.exe) TLS10