FTP 无法列出包含变音字符的目录

FTP can't list a directory containing umlaut character

我正在创建某种 ftp 代理,所以我需要作为客户端访问 ftp,所以我使用了包 ftp。当然,它工作得很好,除了它似乎无法找到带有变音字符的目录。

其实不只是这个包的问题,​​很多ftp客户端好像都有这个问题,我试过ftp.exe, ftp (linux) ,并且他们 return (550-The system cannot find the file specified.) 一些客户端设法能够列出它,例如浏览器 ftp-client(但是它们将被弃用)、Filezilla 或winscp没问题。

OPT UTF-8 ON好像被忽略了500 Command not understood.。服务器确实在 FEAT 中列出了它,谷歌搜索没有用,因为他们只是反驳使用不同的客户端,但我正在 node 中编程。

我不确定是否需要代码,因为问题可能与代码本身无关。


有兴趣者:

var c = new (require("ftp"));
  c.on('ready', function() {
    c.list("ä",function(err, list) {
      if (err) throw err;
/* Uncaught Error: The system cannot find the file specified.
    at makeError (C:\node_modules\ftp\lib\connection.js:1067:13) {
  code: 550
*/
    });
  });
  c.connect(connectsettings);

WinSCP 日志:

. 2021-01-12 16:52:22.576 ä;D;0;2021-01-12T15:47:00.000Z;1;"" [0];"" [0];---------;0
. 2021-01-12 16:52:22.712 Session upkeep
. 2021-01-12 16:52:22.740 Session upkeep
. 2021-01-12 16:52:23.077 Session upkeep
. 2021-01-12 16:52:23.578 Session upkeep
. 2021-01-12 16:52:23.866 Changing directory to "ä".
> 2021-01-12 16:52:23.871 CWD ä
< 2021-01-12 16:52:24.061 250 CWD command successful.
. 2021-01-12 16:52:24.062 Got reply 1 to the command 16
. 2021-01-12 16:52:24.062 Getting current directory name.
> 2021-01-12 16:52:24.062 PWD
< 2021-01-12 16:52:24.257 257 "/ä" is current directory.
. 2021-01-12 16:52:24.257 Got reply 1 to the command 16
. 2021-01-12 16:52:24.257 Retrieving directory listing...
> 2021-01-12 16:52:24.257 TYPE A
< 2021-01-12 16:52:24.452 200 Type set to A.
> 2021-01-12 16:52:24.452 PASV
< 2021-01-12 16:52:24.647 227 Entering Passive Mode (127,0,0,1,239,2).
> 2021-01-12 16:52:24.647 LIST -a
. 2021-01-12 16:52:24.647 Connecting to 127.0.0.1:61186 ...
< 2021-01-12 16:52:24.842 150 Opening ASCII mode data connection.
< 2021-01-12 16:52:25.041 226 Transfer complete.
. 2021-01-12 16:52:25.046 Data connection closed
. 2021-01-12 16:52:25.046 01-12-21  10:47AM                    0 Nuevo documento de texto.txt
. 2021-01-12 16:52:25.047 Directory listing successful
. 2021-01-12 16:52:25.047 Got reply 1 to the command 2
. 2021-01-12 16:52:25.047 ..;D;0;1899-12-30T01:00:00.000Z;0;"" [0];"" [0];---------;0
. 2021-01-12 16:52:25.047 Nuevo documento de texto.txt;-;0;2021-01-12T15:47:00.000Z;1;"" [0];"" [0];---------;0
. 2021-01-12 16:52:25.117 Session upkeep

所以,我设法理解了发生了什么,(感谢一个名为 wireshark 的数据包嗅探工具),这基本上是编码问题的典型案例。对于 ftp 客户端,发生的事情基本上是 ftp 仅接收 latin-1 编码,但节点在幕后将其转换为 utf8。 例如,我的终端设置为 utf-8,所以它一直向 latin-1 服务器发送 utf-8 消息,当然它不知道如何解释。

但我发现了一个命令(在 unix 中)允许您将 utf-8 转换为 latin-1,并且您可以在终端上像这样使用它 >luit -encoding ISO-8859-1 ftp 这会将 utf-8 转换为 latin-1,然后成功列出文件。

现在对于 node-js 的情况,我唯一要做的就是阻止 node-js 将字符串转换为 UTF-8,并将其转换为 latin-1。然而,库对 utf-8 字符串进行了硬编码,因此,我不得不选择、修改库或搜索支持此类编码的替代方案。

令人惊讶的是,我不得不做后一个,因为我没有找到另一个 ftp 库,我有幸找到了 @icetee/ftp, which is a fork of the original ftp package. Basically I had to make a fork and modify this line。现在一切都适用于我的服务器,希望这个包的未来会有一个设置。我就是这样解决的。