FtpWebRequest返回"550文件不可用(例如,文件未找到,无法访问)".将ListDirectoryDe​​tails用于存在的目录时 [英] FtpWebRequest returning "550 File unavailable (e.g. file not found, no access)" when using ListDirectoryDetails for a directory that exists

查看:234
本文介绍了FtpWebRequest返回"550文件不可用(例如,文件未找到,无法访问)".将ListDirectoryDe​​tails用于存在的目录时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个烦人的问题,无法在FTP中获取所需的文件.该文件的名称可能有所不同,因此我需要先访问该文件夹,然后在其中列出文件,然后直接向该文件发出请求.

I have an annoying problem preventing me to get a file I need in an FTP. This file may have differents names so I need to access the folder first and list files inside to do a request directly to the file then.

我的问题是,例如,我可以在Filezilla中访问此文件,并且可以完美地发现该文件夹,但是当使用FtpWebResponse实例获取该文件夹时,出现错误550

My problem is that I can access this file in Filezilla for example, and perfectly discovers the folder as well, but when using an FtpWebResponse instance to get the folder, I have an error 550

550文件不可用(例如,找不到文件,无法访问)

550 File unavailable (e.g. file not found, no access)

这是代码:

FtpWebRequest wr = (FtpWebRequest)WebRequest.Create("ftp://ftp.dachser.com/data/edi/kunden/da46168958/out");

wr.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

wr.Credentials = new NetworkCredential("login", "password");

FtpWebResponse response = (FtpWebResponse)wr.GetResponse();

Stream reponseStream = response.GetResponseStream();

StreamReader reader = new StreamReader(reponseStream);

string names = reader.ReadToEnd();

FtpWebResponse响应=(FtpWebResponse)wr.GetResponse();

FtpWebResponse response = (FtpWebResponse)wr.GetResponse();

是该行引发错误

PS:生产,测试和FileZilla位于同一域,使用相同的Internet连接(如果有帮助)

PS: Production, tests and FileZilla are on the same domain, using the same internet connection (if it helps)

感谢您的关注和反馈

FileZilla日志:

The FileZilla logs:

我程序中的日志,用红色圈出的错误与FTP错误无关

Logs from my program, error circled in red isn't related to FTP error

推荐答案

FtpWebRequest解释URL时,它不会将将主机名和路径分开的斜杠视为路径的一部分.然后将提取的路径按原样与FTP CWD命令一起使用.这意味着FTP服务器将解析相对于您的主目录的路径.如果您的帐户没有被chroot(客户不将房屋视为根),则缺少前导斜线会导致意外行为.

When FtpWebRequest interprets the URL, it does not consider the slash that separates the hostname and the path as a part of the path. The extracted path is then used with FTP CWD command as is. That means that the FTP server will resolve the path relatively to your home directory. If your account is not chrooted (the home is not seen as the root by the client), the lack of the leading slash leads to unexpected behaviour.

在您的情况下,您从/remote/path开始,并使用类似ftp://example.com/remote/path/的URL,它将尝试更改为remote/path,因此最终更改为/remote/path/remote/path.那不是你想要的.

In your case, you start in /remote/path and with URL like ftp://example.com/remote/path/, it will try to change to remote/path, so ultimately to /remote/path/remote/path. That's not what you want.

  • 您必须使用相对路径到主文件夹.您的情况意味着使用没有任何路径的URL.
  • 或者使用绝对路径,您需要在主机名后使用两个斜杠:ftp://example.com//remote/path/.

还要注意,指向文件夹的URL应该以斜杠结尾:为什么FtpWebRequest返回此现有目录的空流?

Also note that an URL to a folder should end with a slash: Why does FtpWebRequest return an empty stream for this existing directory?

有关其他550个问题,请参见 FtpWebRequest返回错误550文件不可用

For other 550 problems, see FtpWebRequest returns error 550 File unavailable

这篇关于FtpWebRequest返回"550文件不可用(例如,文件未找到,无法访问)".将ListDirectoryDe​​tails用于存在的目录时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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