3

我有 Node.js 应用程序,我正在尝试连接到 FTP 服务器并列出 FTP 服务器文件夹中的文件夹/文件。

服务器配置有:TLS/SSL 隐式加密

这是我的代码:

async function listFilesInFtpFolder() {
  const client = new ftp.Client()
  client.ftp.verbose = true;
  try {
      await client.access({
          host: ftpConfig.host,
          user: ftpConfig.user,
          password: ftpConfig.password,
          port: ftpConfig.port,
          secure: false
      });

      // ********************** NOTE **********************
      // The execution never reaches here, it gets stuck in the 
      // ... previous statement until it times out
      // ********************** NOTE **********************

      console.log('connected');
      console.log(await client.list())

  }
  catch(err) {
      console.log(err)
  }
  client.close()
}

收到此错误:

Listening on port 3001
Connected to 155.66.22.88:6610

Error: Timeout (control socket)
    at Socket.<anonymous> (C:\Dev\my-app\node_modules\basic-ftp\dist\FtpContext.js:296:58)
    at Object.onceWrapper (events.js:298:28)
    at Socket.emit (events.js:209:13)
    at Socket._onTimeout (net.js:468:8)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)

执行永远不会到达这些行:

      console.log('connected');
      console.log(await client.list())

它一直在等待访问方法,直到超时由于某种奇怪的原因,访问方法报告“已连接”

请注意,如果我使用 WinSCP ( https://winscp.net/ ) 之类的程序连接到此 FTP 服务器,我可以连接并查看文件夹。但由于某些奇怪的原因,我无法从 nodejs 连接。我也尝试了许多 FTP 库。

4

2 回答 2

1

Node.js 似乎不支持隐式TLS/SSL。

参见例如:
https ://github.com/mscdex/node-ftp/issues/153

您确定您的服务器不支持显式TLS/SSL 吗?

于 2019-10-19T18:54:11.727 回答
0

假设您正在使用ftp来自 npm 的模块

根据文档https://www.npmjs.com/package/ftp#methods选项接受混合类型 ,secure尝试“隐式”

安全 - 混合 - 设置为 true 用于控制和数据连接加密,“控制”仅用于控制连接加密,

或 'implicit' 用于隐式加密控制连接(此模式在现代已弃用,但通常使用端口 990)默认值:false

于 2019-10-28T09:34:52.447 回答