我试图使用以下代码获取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命令,要求启动显式FTPS会话.
在您的情况下,您必须配置Filezilla Server以使用显式FTPS.该程序记录于Filezilla Wiki