【问题标题】:C# FTP with WebClient Error: The remote server returned an error: (534) 534 Policy requires SSLC# FTP with WebClient Error: The remote server returned an error: (534) 534 Policy requires SSL
【发布时间】:2018-06-28 21:10:42
【问题描述】:

我的代码的目的是将一些数据上传到 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);
}

【问题讨论】:

    标签: c# .net ftp webclient ftps


    【解决方案1】:

    Afaik,WebClient 本身不支持 FTP over TLS (FTPS)(它实际上确实支持它内部,但没有 API 来启用它的使用)。

    设置ServicePointManager.SecurityProtocol 无济于事。并且绝对不要将其设置为SecurityProtocolType.Ssl3


    【讨论】:

    • 我尝试使用 FtpWebRequest。但我得到了System Error的例外@
    • FtpWebRequest 代码:byte[] data = stream.ToArray(); FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create("ftp://url); ftpRequest.Method = WebRequestMethods.Ftp.UploadFile; ftpRequest.Credentials = new NetworkCredential("**", "**"); ftpRequest.EnableSsl = true; ftpRequest.UseBinary = true; ftpRequest.UsePassive = false; ftpRequest.KeepAlive = true; ftpRequest.ContentLength = data.Length; using (Stream requestStream = ftpRequest.GetRequestStream()) { requestStream.Write(data, 0, data.Length); }
    • 我们需要更多细节。从异常调用堆栈和完整的异常消息开始。 + 为什么ftpRequest.UsePassive = false;
    • 使用 FtpWebRequest 是继续这个的方法。我的系统管理员必须在服务器上为我的 ftp 客户端启用 FTPS 协议。
    猜你喜欢
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    • 2012-03-14
    • 1970-01-01
    • 2019-01-22
    • 2021-09-07
    • 2022-11-20
    • 2021-08-16
    相关资源
    最近更新 更多