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 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)