gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:12:45 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com