简体   繁体   English

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

[英]SSL Certificate Issue - The remote certificate is invalid according to the validation procedure

I'm getting the following error when trying to upload a file to my server via C# desktop application: "The remote certificate is invalid according to the validation procedure." 尝试通过C#桌面应用程序将文件上传到我的服务器时出现以下错误:“根据验证程序,远程证书无效。” This has something to do with the SSL Certificate. 这与SSL证书有关。 It's for my website which is hosted by Arvixe. 它是由我的网站由Arvixe托管。 Here is the code I use: 这是我使用的代码:

        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();
    }

This code works fine if I set request.EnableSsl = false. 如果我设置request.EnableSsl = false,此代码可以正常工作。 I'm not sure what to do. 我不知道该怎么做。 I've tried setting the URI to ftps:// and sftp://, but they return the error "The URI prefix is not recognized." 我已经尝试将URI设置为ftps://和sftp://,但它们返回错误“无法识别URI前缀”。 any help is appreciated. 任何帮助表示赞赏。

Hard to test your code as it connects to a public service. 连接到公共服务时难以测试代码。 But if you just want to ignore the SSL error perhaps this can help you do that: 但是如果你只是想忽略SSL错误,也许这可以帮助你做到这一点:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据SSL Restful Service的验证过程,远程证书无效 - The remote certificate is invalid according to the validation procedure from SSL Restful Service “根据验证程序,远程证书无效” wcf - “The remote certificate is invalid according to the validation procedure” wcf AuthenticateAsServer - 根据验证过程,远程证书无效 - AuthenticateAsServer - The remote certificate is invalid according to the validation procedure FluentFTP:根据验证程序远程证书无效 - FluentFTP: The remote certificate is invalid according to the validation procedure 根据使用自签名证书的验证程序,远程证书无效 - The remote certificate is invalid according to the validation procedure with self-signed certificate 通过C#驱动程序的MongoDB ssl:根据验证过程,远程证书无效 - MongoDB ssl via C# driver: The remote certificate is invalid according to the validation procedure 根据使用imap的验证程序,远程证书无效 - the remote certificate is invalid according to the validation procedure using imap TCP客户端C#:根据验证过程,远程证书无效 - TCP Client C#: The remote certificate is invalid according to the validation procedure Microsoft GraphServiceClient 返回“根据验证程序远程证书无效” - Microsoft GraphServiceClient returns "remote certificate is invalid according to the validation procedure" 获取令牌时出错“根据验证过程,远程证书无效” - Error when get token “The remote certificate is invalid according to the validation procedure”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM