我正在尝试通过 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 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!