C# FTP 550 错误

C# FTP 550 error(C# FTP 550 错误)
本文介绍了C# FTP 550 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试通过 FTP 以编程方式下载 C# 中的文件,这里是相关代码(显然带有假凭据和 URI):

I'm trying to programatically download a file in C# via FTP, here is the relevant code (obviously with fake credntials and URI):

try
{
    var request = FtpWebRequest.Create("ftp://ftp.mydomain.com/folder/file.zip");
    request.Credentials = new NetworkCredential("username", "password");

    using (var response = request.GetResponse())
    {
         ...
    }
}
catch (WebException we)
{
    ...
}

request.GetResponse() 处引发异常,错误代码为 550.问题不在于凭据或 URI,因为它们在 IE 中运行良好并且文件下载成功在那里.我错过了什么?我应该使用其他类型的凭证对象吗?request 对象上是否有我未设置的属性?任何帮助将不胜感激.

The exception is thrown at request.GetResponse(), and the error code is 550. The issue is not with the credentials or the URI, as they work just fine in IE and the file downloads successfully there. What am I missing? Is there some other kind of credential object I should be using? Is there a property on the request object I'm not setting? Any help would be appreciated.

推荐答案

原来FTP根不一定和URL根一样.也许我混淆了术语,所以让我解释一下:在我的例子中,连接到 ftp.mydomain.com 已经从/folder 开始,所以我的 URL 只需 ftp://ftp.mydomain.com/file.zip.IE8 知道如何消除原始路径中多余的/folder 部分,而 FtpRequest 类不知道,这就是为什么它在 IE8 中有效,但在 C# 代码中无效.

Turns out the FTP root isn't necessarily the same as the URL root. Perhaps I'm mixing up terminology, so let me explain: in my case, connecting to ftp.mydomain.com already starts at /folder, so my URL needed to just be ftp://ftp.mydomain.com/file.zip. IE8 knows how to eliminate the redundant /folder part in the original path while the FtpRequest class does not, which is why it worked in IE8 but not in the C# code.

这篇关于C# FTP 550 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Custom Error Queue Name when using EasyNetQ for RabbitMQ?(使用 EasyNetQ for RabbitMQ 时自定义错误队列名称?)
How to generate password_hash for RabbitMQ Management HTTP API(如何为 RabbitMQ 管理 HTTP API 生成密码哈希)
Rabbitmq Ack or Nack, leaving messages on the queue(Rabbitmq Ack 或 Nack,将消息留在队列中)
Setup RabbitMQ consumer in ASP.NET Core application(在 ASP.NET Core 应用程序中设置 RabbitMQ 消费者)
Specify Publish timeouts in mass transit(指定公共交通中的发布超时)
RabbitMQ asynchronous support(RabbitMQ 异步支持)