The purpose of my code is to upload some data to a FTP location.
With my code I keep getting an error stating that the remote server requires SSL. I am using a .NET version greater then 4. All the other posts suggest I add the ServicePointManager
code that I have below.
The exception occurs on client.UploadData
.
Still no dice. Any help would be very much appreciated.
ServicePointManager.ServerCertificateValidationCallback +=
(sender,certificate, chain, sslPolicyErrors) => true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
byte[] data = stream.ToArray(); //Data I want to upload to FTP location
using (WebClient client = new WebClient())
{
client.Credentials = new NetworkCredential("*Username*", "*Password*");
client.UploadData("ftp://file.example.com/Content/file", "STOR", data);
}
Afaik, WebClient
does not support FTP over TLS (FTPS) natively (it actually does support it internally, but has no API to enable its use).
Setting ServicePointManager.SecurityProtocol
cannot help. And definitely do not set it to SecurityProtocolType.Ssl3
!
ftps://
prefix as shown for example here: Force WebClient to use SSL.or instead of WebClient
, use FtpWebRequest
, which supports FTP over TLS natively.
Use a code like this:
Upload and download a binary file to/from FTP server in C#/.NET
And just add
request.EnableSsl = true;