C# FTP with WebClient Error: The remote server returned an error: (534) 534 Policy requires SSL
C# FTP with WebClient Error: The remote server returned an error: (534) 534 Policy requires SSL
我的代码的目的是将一些数据上传到 FTP 位置。
在我的代码中,我不断收到一条错误消息,指出远程服务器需要 SSL。我正在使用大于 4 的 .NET 版本。所有其他帖子都建议我添加下面的 ServicePointManager
代码。
异常发生在client.UploadData
。
仍然没有骰子。非常感谢任何帮助。
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
不支持 FTP over TLS (FTPS) 本机(它实际上支持它 内部 ,但是没有 API 来启用它。
设置ServicePointManager.SecurityProtocol
无济于事。绝对不要将其设置为 SecurityProtocolType.Ssl3
!
- 要么注册
ftps://
前缀,如下所示:Force WebClient to use SSL.
或使用 FtpWebRequest
而不是 WebClient
,它原生支持 FTP over TLS。
使用这样的代码:
然后添加
request.EnableSsl = true;
我的代码的目的是将一些数据上传到 FTP 位置。
在我的代码中,我不断收到一条错误消息,指出远程服务器需要 SSL。我正在使用大于 4 的 .NET 版本。所有其他帖子都建议我添加下面的 ServicePointManager
代码。
异常发生在client.UploadData
。
仍然没有骰子。非常感谢任何帮助。
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
不支持 FTP over TLS (FTPS) 本机(它实际上支持它 内部 ,但是没有 API 来启用它。
设置ServicePointManager.SecurityProtocol
无济于事。绝对不要将其设置为 SecurityProtocolType.Ssl3
!
- 要么注册
ftps://
前缀,如下所示:Force WebClient to use SSL. 或使用
FtpWebRequest
而不是WebClient
,它原生支持 FTP over TLS。使用这样的代码:
然后添加
request.EnableSsl = true;