【发布时间】:2019-10-18 21:13:29
【问题描述】:
我有 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 库。
【问题讨论】:
-
有人知道我为什么无法连接吗?
-
"FTP 服务器配置为:TLS/SSL 隐式加密",但是你设置了
secure: false? -
@BenBeri 无论我将其设置为真还是假,结果都相同。这是此属性的文档:“(property) AccessOptions.secure?: boolean Use explicit FTPS over TLS. Optional, default is false.”
-
你确定这个端口吗?
-
@MohammedNagy 是的 100% 确定端口,正如我所说,如果我使用 WinSCP 之类的程序进行连接,它可以正常工作,但由于某种原因,它不能从 Node.js 工作,我想不通为我的一生而奋斗。
标签: javascript node.js reactjs ftp ftps