SSL证书问题 - 根据验证过程,远程证书无效

3

当我尝试通过C#桌面应用程序将文件上传到服务器时,出现以下错误:“根据验证过程,远程证书无效。” 这与SSL证书有关。它是为我的由Arvixe托管的网站而设计的。 这是我使用的代码:

        public void Upload(string strFileToUpload)
    {
        FileInfo fiToUpload = new FileInfo(strFileToUpload);
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.sd.arvixe.com/" + strDomain + "/wwwroot/OnlineGalleries/" + strOnlineGalleryName + "/Gallery/" + fiToUpload.Name);
        request.EnableSsl = true;
        request.Method = WebRequestMethods.Ftp.UploadFile;
        request.Credentials = new NetworkCredential("usr", "psw");
        Stream sFTP = request.GetRequestStream();
        FileStream file = File.OpenRead(strFileToUpload);
        int length = 1024;
        byte[] buffer = new byte[length];
        int bytesRead = 0;
        do
        {
            bytesRead = file.Read(buffer, 0, length);
            sFTP.Write(buffer, 0, bytesRead);
        }
        while (bytesRead != 0);
        file.Close();
        sFTP.Close();
    }

如果将request.EnableSsl = false,则此代码可以正常工作。我不知道该怎么办。我尝试将URI设置为ftps://和sftp://,但它们返回错误“未识别的URI前缀”。感谢您的帮助。


http://ftps.codeplex.com/ 检查是否达到了此处记录的 FtpWebRequest 的限制。sftp不是 ftps。确保您前往维基百科并学习它们之间的区别。 - Lex Li
1个回答

11

如果你的代码连接到公共服务,很难测试。但如果你只是想忽略SSL错误,这可能会帮助你做到这一点:

System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接