C# FTP 550 error(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 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# FTP 550 错误
基础教程推荐
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
