带通配符的 FTP 目录部分列表
首先我问: ftp 目录列出超时。大量的子目录。我得到了答案。
尽管如此,因为目录中可能有数十万个 FTP 对象,所以扫描它可能需要很长时间。不过,我认为可能检索以“A”开头,然后是“B”等的所有对象...当它检索目录时,它可以开始在另一个线程上处理它们,而无需等到它获取整个列表。
是否可以使用标准 FtpWebRequest
使用通配符列出 FTP 目录?
First I asked that: ftp directory listing timeout. Huge number of subdirs. I got the answer.
Still because I can have hundred thousands of FTP objects in the directory it could take really long time to scan that. However I thought it might be possible to retrieve all the objects that begin with 'A' and then 'B' and so on... As it retrieves directories it could start processing them on the other thread without waiting till it gets the entire list.
Is it possible to do FTP directory listing with wildcards using standard FtpWebRequest
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
FTP 规范 (RFC 3659) 的最新更新明确禁止它。来自该规范的第 2.2.2 节,标题为“通配符”(强调我的):
也就是说,如果您的服务器支持它,您仍然可以使用
FtpWebRequest
类,但您必须自己处理响应才能处理项目列表,因为 .NET 类无法理解您的服务器 -具体扩展。The most recent update to the FTP specification (RFC 3659) explicitly forbids it. From section 2.2.2 of that specification, titled "Wildcarding" (emphasis mine):
That said, if your server supports it, you could still use the
FtpWebRequest
class, but you'd have to process the response yourself to handle the list of items, as the .NET classes won't understand your server-specific extensions.FTP 规范规定文件列表命令(
LIST
、NLIST
、MLSD
等)的参数是路径名。所以无论如何都不应该有通配符。RFC 959 (
LIST
+NLIST):
RFC 3659 (
MLSD
):实际上,尽管许多 FTP 服务器确实支持参数中的通配符。但由于规范不允许这样做,因此显然对于支持的通配符没有设定标准。
vsftpd 支持
*
、?
和{}
以及LIST
。 vsftpd 不支持现代的 MLSD。proftpd 支持
*
、?
和[]
。但仅适用于LIST
。它明确不允许使用带有注释的现代 MLSD 通配符:pureftpd 支持
*
、?
和[]
用于LIST
和 <代码>MLSD。FileZilla 服务器 仅支持
LIST
和MLSD
的*
。但一般来说,您根本不应该依赖 FTP 服务器来支持任何通配符。
唯一可靠的方法是检索完整的目录列表并在本地过滤文件。例如,您可以使用正则表达式(
正则表达式
类)The FTP specification says that the argument to file listing commands (
LIST
,NLIST
,MLSD
, etc) is a pathname. So there should be NO wildcard, whatsoever.RFC 959 (
LIST
+NLIST
):RFC 3659 (
MLSD
):In practice though many FTP servers do support wildcards in the argument. But as the specification does not allow that, there's obviously no set standard for the wildcards supported.
vsftpd supports
*
,?
and{}
with theLIST
. vsftpd does not support the modernMLSD
.proftpd supports
*
,?
and[]
. But for theLIST
only. It explicitly does not allow wildcards with the modernMLSD
with a comment:pureftpd supports
*
,?
and[]
for both theLIST
and theMLSD
.FileZilla server supports
*
only for both theLIST
and theMLSD
.But in general, you should not rely on the FTP server to support any wildcards at all.
The only reliable approach to is to retrieve a complete directory listing and filter the files locally. For example you can use a regular expression (the
Regex
class)