Search code examples
c#.netftpwebclientftps

C# FTP with WebClient Error: The remote server returned an error: (534) 534 Policy requires SSL


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);
}

Solution

  • 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!