SSL证书问题 - 远程证书按验证程序是无效的 [英] SSL Certificate Issue - The remote certificate is invalid according to the validation procedure

查看:384
本文介绍了SSL证书问题 - 远程证书按验证程序是无效的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过C#桌面应用程序将文件上传到我的服务器时,收到以下错误:远程证书按验证程序是无效的。因此有必要做的SSL证书。这对我的网站,该网站是由Arvixe主办。这里是我使用的代码:

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." This has something to do with the SSL Certificate. It's for my website which is hosted by 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();
    }

这代码,如果我设置request.EnableSsl =假工作正常。我不知道该怎么办。我已经试过URI设置为FTPS://和SFTP://,但他们会返回错误的URI前缀无法识别。任何帮助表示赞赏。

This code works fine if I set 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." any help is appreciated.

推荐答案

硬盘来测试你的代码,因为它连接到一个公共服务。但是,如果你只是想忽略SSL错误或许这可以帮助你做到这一点:

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:

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

这篇关于SSL证书问题 - 远程证书按验证程序是无效的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆