尝试连接时,FTPS会抛出“服务器提交协议违规”错误

时间:2013-07-05 14:52:30

标签: c# .net ssl ftpwebrequest ftps

我正在开发一个小应用程序来通过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;
}

0 个答案:

没有答案