我应该如何在 FTP 服务器中处理 LIST 命令?
我正在用Java编写一个FTP服务器,现在我想回答LIST命令。仅发送文件名就足够了,我不需要发送文件大小、所有者、权限等。似乎只发送一些字符串作为文件名不能满足客户端的要求(我尝试了 ASCII 和二进制格式)。我如何知道 FTP 客户端期望的回复是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果要创建兼容的 FTP 服务器,则需要处理 LIST 和 NLST(标准命令)以及 MLST 和 MLSD 扩展命令。
LIST 命令的格式没有在任何地方定义,世界上大约有 400 种格式。使用 Unix ls 格式或 Windows DIR 格式适用于大多数客户端,因为这些格式非常普遍并且受到客户端的良好支持。
NLST 仅是文件名列表。
MLST 和 MLSD 使用 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.
规范的查找位置是相关的 RFC: http://www.ietf.org/rfc/rfc959 不幸的是
,在这个特定的实例中,RFC 相当模糊:
为了确保与现有 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:
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.