我应该如何在 FTP 服务器中处理 LIST 命令?

发布于 2024-11-10 00:11:23 字数 322 浏览 4 评论 0原文

我正在用Java编写一个FTP服务器,现在我想回答LIST命令。仅发送文件名就足够了,我不需要发送文件大小、所有者、权限等。似乎只发送一些字符串作为文件名不能满足客户端的要求(我尝试了 ASCII 和二进制格式)。我如何知道 FTP 客户端期望的回复是什么?

我正在使用 FireFTPFileZilla

I'm writing an FTP server with Java, and now I want to answer to LIST command.Sending only file names is enough, and I don't need to send file size, owner, permission, etc. It seems that just sending some strings, as file names, does not satisfy the client (I tried both ASCII and binary formats). How can I find out what does an FTP client expect as a reply?

I'm testing my server using FireFTP and FileZilla

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘虞初梦 2024-11-17 00:11:23

如果要创建兼容的 FTP 服务器,则需要处理 LIST 和 NLST(标准命令)以及 MLST 和 MLSD 扩展命令。

LIST 命令的格式没有在任何地方定义,世界上大约有 400 种格式。使用 Unix ls 格式或 Windows DIR 格式适用于大多数客户端,因为这些格式非常普遍并且受到客户端的良好支持。

NLST 仅是文件名列表。

MLSTMLSD 使用 RFC 3659 中描述的机器可解析格式(这就是 M 字母代表的格式)。客户端更容易处理,并且支持非常欢迎。

If you want to create a compatible FTP server, you need to handle LIST and NLST (standard commands) and also MLST and MLSD extension commands.

Format for LIST command is not defined anywhere and there are about 400 formats encountered in the world. Using Unix ls format or Windows DIR format would work with most clients as these are formats quite widespread and well supported by the clients.

NLST is the list of file names only.

MLST and MLSD use the machine-parseable format (this is what M letter stands for) which is described in RFC 3659. It's easier for the clients to handle and it's support is very welcome.

向日葵 2024-11-17 00:11:23

规范的查找位置是相关的 RFC: http://www.ietf.org/rfc/rfc959 不幸的是

,在这个特定的实例中,RFC 相当模糊:

        Since the information on a file may vary widely from system
        to system, this information may be hard to use automatically
        in a program, but may be quite useful to a human user.

为了确保与现有 FTP 客户端的兼容性,最好的选择是查看一些广泛部署的 FTP 服务器软件并模拟其输出格式。

The canonical place to look is the relevant RFC: http://www.ietf.org/rfc/rfc959.txt

Unfortunately, in this particular instance the RFC is pretty vague:

        Since the information on a file may vary widely from system
        to system, this information may be hard to use automatically
        in a program, but may be quite useful to a human user.

In order to ensure compatibility with existing FTP clients, your best bet is to look at some widely-deployed FTP server software and emulate the format of its output.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文