0

我正在开发一个小型应用程序来通过 ftps 隐式 ssl 上传文件,但我已经到了尝试连接的地步,我发现错误说“底层连接已关闭:服务器违反了协议”。

我一直在寻找解决方案,但找不到任何东西。我已经复制了下面的代码。

代码到达FtpWebResponse response = (FtpWebResponse)request.GetResponse()并挂起,直到它落入陷阱。

还要注意字符串状态字段在异常期间返回 null。

string ftps = "ftp://100.0.0.1:990/Test"

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftps);
request.KeepAlive = true;
request.EnableSsl = true;
request.UsePassive = true;
request.UseBinary = true;
request.Credentials = new NetworkCredential("user", "Password");

ServicePointManager.ServerCertificateValidationCallback = new  RemoteCertificateValidationCallback(ValidateCertificate);


try
{
    FtpWebResponse response = (FtpWebResponse)request.GetResponse();
    request.Method = WebRequestMethods.Ftp.UploadFile;
}
catch (WebException e)
{
    String status = ((FtpWebResponse)e.Response).StatusDescription;
}




private bool ValidateCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
     return true;
}
4

0 回答 0