简体   繁体   中英

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

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM