[英]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. 我的代码的目的是将一些数据上传到FTP位置。
With my code I keep getting an error stating that the remote server requires SSL. 通过我的代码,我不断收到错误消息,指出远程服务器需要SSL。 I am using a .NET version greater then 4. All the other posts suggest I add the
ServicePointManager
code that I have below. 我使用的是大于4的.NET版本。所有其他帖子建议我添加下面的
ServicePointManager
代码。
The exception occurs on client.UploadData
. 该异常发生在
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). Afaik,
WebClient
本身不支持TLS上的FTP(FTPS)(实际上内部支持,但没有API来启用它)。
Setting ServicePointManager.SecurityProtocol
cannot help. 设置
ServicePointManager.SecurityProtocol
无法帮助。 And definitely do not set it to SecurityProtocolType.Ssl3
! 绝对不要将其设置为
SecurityProtocolType.Ssl3
!
ftps://
prefix as shown for example here: Force WebClient to use SSL . ftps://
前缀,如此处所示: 强制WebClient使用SSL 。 or instead of WebClient
, use FtpWebRequest
, which supports FTP over TLS natively. 或代替
WebClient
,使用FtpWebRequest
,它本身支持基于TLS的FTP。
Use a code like this: 使用如下代码:
Upload and download a binary file to/from FTP server in C#/.NET 在C#/。NET中向FTP服务器上载二进制文件或从FTP服务器下载二进制文件
And just add 然后添加
request.EnableSsl = true;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.