I'm trying to upload a file to FTP server using SSL certificate, but receives WebException with the following message: 'The remote server returned an error: (501) Syntax error in parameters or arguments.
The code I'm using to send a file is the following:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(uri));
request.Credentials = new NetworkCredential(user, pass);
request.KeepAlive = false;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UseBinary = true;
request.UsePassive = false;
request.ContentLength = fileInf.Length;
request.EnableSsl = true;
request.ClientCertificates = new X509CertificateCollection { X509Certificate.CreateFromCertFile(@".\TestVM2.cer") };
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => { return true; };
strm = request.GetRequestStream();
The SSL settings on the FTP server contain the corresponding certificate and SSL Policy is set to "Allow SSL connections".
Why do I get the exception and how to solve it?
What I have tried:
1. The code without the 3 problematic lines
request.EnableSsl = true;
request.ClientCertificates = new X509CertificateCollection { X509Certificate.CreateFromCertFile(@".\TestVM2.cer") };
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => { return true; };
works perfectly.