C#FTP 550错误 [英] C# FTP 550 error

查看:186
本文介绍了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中正常工作并且成功下载文件那里。我错过了什么?我应该使用一些其他类型的凭证对象吗?我没有设置请求对象的属性吗?任何帮助将不胜感激。

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已经开始在/文件夹,所以我的URL只需要 ftp://ftp.mydomain.com/file.zip 。 IE8知道如何消除原路径中的冗余/文件夹部分,而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错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆