Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

ssl

ftp

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.

like image 676
Vandel212 Avatar asked Feb 03 '26 07:02

Vandel212


1 Answers

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;
like image 100
Mattias Lindberg Avatar answered Feb 04 '26 22:02

Mattias Lindberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!