Delphi Indy FTP 列表方法中的错误?

标签 delphi ftp indy

我正在尝试生成与特定文件掩码匹配的文件列表,但 Indy 因此错误而失败

EidReplyRFCError with message '.': No such file or directory.

我尝试了几种变体,结果如下:

FTP.List( aFiles, '', true ); => 这有效

FTP.List( aFiles, '*.*', false ); => 这也有效

FTP.List( aFiles, '*.*', true ); => 失败

FTP.List( aFiles, '*.zip', true ); => 这也失败了(尽管它是最新文档中的示例)

FTP.List( '*.*', false ); => 这有效

FTP.List( '*.*', true ); => 失败

我正在使用 Delphi XE5 和 Indy 版本 10.6。如果相关的话,XE8 中也存在同样的问题。

也许功能已经改变,文档现在是错误的,或者是 Indy 中的一个错误?

我需要“详细信息”,以便我也可以比较时间戳和大小。

最佳答案

这不是 TIdFTP 中的错误。这更像是 Indy 文档中的一个遗漏。

EIdReplyRFCError 表示 FTP 服务器本身在响应 TIdFTP.List() 发送的命令时报告错误。根据 ADetails 参数的值和 TIdFTPUseMLIS+CanUseMLS 属性,List( ) 可以发送三个不同命令之一:

ADetails=False:

    NLST [ASpecifier]

ADetails=True:

  TIdFTP.UseMLIS=True and TIdFTP.CanUseMLS=True:

    MLSD [ASpecifier]

  TIdFTP.UseMLIS=False or TIdFTP.CanUseMLS=False:

    LIST [ASpecifier]

因此:

FTP.List( aFiles, '', true ); // this works
// sends either 'LIST' or 'MLSD'

FTP.List( aFiles, '*.*', false ); // this works too
// sends 'NLST *.*'

FTP.List( aFiles, '*.*', true ); // this fails
// sends either 'LIST *.*' or 'MLSD *.*'

FTP.List( aFiles, '*.zip', true ); // this fails too
// sends either 'LIST *.zip' or 'MLSD *.zip'

FTP.List( '*.*', false ); // this works
// sends 'NLST *.*'

FTP.List( '*.*', true ); // this fails
// sends either 'LIST *.*' or 'MLSD *.*'

请注意,所有“失败”的命令都有一些共同点 - 它们可能会发送 MLSD ASpecifier 命令。

RFC 959 ,它定义了 LISTNLST 命令:

LIST (LIST)

This command causes a list to be sent from the server to the passive DTP. If the pathname specifies a directory or other group of files, the server should transfer a list of files in the specified directory. If the pathname specifies a file then the server should send current information on the file. A null argument implies the user's current working or default directory. ...

NAME LIST (NLST)

This command causes a directory listing to be sent from server to user site. The pathname should specify a directory or other system-specific file group descriptor; a null argument implies the current directory. ...

RFC 3659 ,它定义了 MLSD 命令:

The MLST and MLSD commands each allow a single optional argument. This argument may be either a directory name or, for MLST only, a file name. For these purposes, a "file name" is the name of any entity in the server NVFS which is not a directory. Where TVFS is supported, any TVFS relative pathname valid in the current working directory, or any TVFS fully qualified pathname, may be given. If a directory name is given then MLSD must return a listing of the contents of the named directory, otherwise it issues a 501 reply, and does not open a data connection. ...

If no argument is given then MLSD must return a listing of the contents of the current working directory, and MLST must return a listing giving information about the current working directory itself. ...

...

If the Client-FTP sends an invalid argument, the server-FTP MUST reply with an error code of 501.

*.**.zip 不是目录名称,因此如果 TIdFTP.List() 发送 MLSD *.*MLSD *.zip 命令。因此,按理说, TIdFTP.UseMLISTIdFTP.CanUseMLS 在您的情况下可能都是 True (UseMLIS 默认情况下为 True,并且 CanUseMLS 在现代 FTP 服务器上通常为 True)。

MLSD 命令不像 LIST/NLST 命令那样支持服务器端过滤。因此,您不能将 *.**.zipMLSD 一起使用。您必须检索完整的目录列表,然后忽略您不感兴趣的任何条目。否则,请在调用 TIdFTP.List() 之前将 TIdFTP.UseMLIS 设置为 False ,但是您会面临 TIdFTP.DirectoryListing 错误地解析某些服务器的目录列表的风险,因为 LIST 命令使用的格式从未标准化,并且有数百种整个互联网上使用的自定义格式(以及为什么 Indy 10 中的 TIdFTP 在使用 LIST 时包含数十个列表解析器)。与 MLSx 不同,MLSx 具有标准化格式(这就是为什么首先引入它,以取代 LIST 的缺点)。

因此,这一切归结为 - 当 TIdFTP.UseMLISTIdFTP.CanUseMLS 均为 True 时,ASpecifier 必须为空或目录,不能文件掩码。

TIdFTP.List() documentation 确实声明List()可以在内部调用TIdFTP.ExtListDir()发送 MLSD 命令,但它没有具体提及在这种情况下对 ASpecifier 参数的特殊限制:

If CanUseMLS contains True, the ExtListDir is called to capture and store the results of the FTP MLSD command in the ADest parameter variable instead of the LIST or NLST commands. No additional processing is performed in the List method under this circumstance, and the method is exited.

When ADetails is False, only the file or directory name is returned in the ADest string list using the FTP NLST command. When ADetails is True, List can return FTP server-dependent details including the file size, date modified, and file permissions for the Owner, Group, and User using the FTP LIST command.

TIdFTP.ExtListDir() documentation 确实声明其输入参数必须是目录名称:

The MLSD command, supported in ExtListDir, accepts an optional directory name or relative path in Adirectory for the directory listing. If am empty string is passed in ADirectory, the current directory is used for the directory listing operation.

附带说明:TIdFTP.DirFormat 属性将告诉您在 TIdFTP.DirectoryListing 解析结果后检测到哪种列表格式。或者您可以查看 TListFTP.ListResultDetailsUsedMLS 属性(将其类型转换为 TIdFTPListResult 来访问属性)以推断 TIdFTP.List() 发送了哪个命令(如果成功)。

关于Delphi Indy FTP 列表方法中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30867501/

相关文章:

delphi - 为项目组织多个 Delphi 库包的最佳方式是什么?

php - 没有人拥有者(99 99)在FTP中由php功能引起?

delphi - 一个 session 中的多个请求 (TidHTTP)

delphi - 如何在 Delphi 中将事件附加到 IHTMLDocument2 链接元素?

delphi - TTimer 的准确度如何?

multithreading - Delphi - 在单次成功执行或用户取消后终止线程

c# - 在 C# 中从 FTP 服务器中删除目录内容

java - 无法使用 Java FTP 客户端下载具有阿拉伯名称的文件

web-services - 使用 TidHTTPServer 以安全的方式处理 GET 请求

delphi - 如何用 Indy 的 TIdHTTPServer 组件替换浏览器 URL?