nodejs ftp-srv:“SocketError:给定的地址不是你的

问题描述 投票:0回答:1

我正在创建一个 cli 脚本,以使用本地 ftp 服务器和 ngrok 隧道在用户之间共享文件。

我有这段代码可以启动服务器,但从 filezilla 无法正确连接。

#!/usr/bin/env node

/**
 * Simple cli FTP files sharing script
 */
const path = require('path');
const ngrok = require('ngrok');
const FtpServer = require('ftp-srv');

const sharedFolder = path.format({dir: __dirname, base: '/shared'})
const ftpAddress = 'ftp://127.0.0.1:21021';


const ftpServer = new FtpServer({
    url: ftpAddress,
    anonymous: true,
    greeting: 'Hello user!'
});

ftpServer.on('login', (data, resolve, reject) => {
    console.log(data);
    resolve({root: sharedFolder});
});

ftpServer.listen().then( async () => {
    const tunnel = await ngrok.connect({proto: 'tcp', addr: 21021});
    console.log(`FTP Server is running on ${ftpAddress}, pubilc tunnel link is: ${tunnel}`);
});

在 VS 控制台中,当脚本运行时,在 filezilla 使用从 ngrok 生成的隧道链接连接到服务器后,我收到此错误。我也看不到欢迎信息。

":"127.0.0.1","directive":"PORT","level":50,"err":{"message":"The given address is not yours","name":"SocketError","stack":"SocketError: The given address is not yours

更新

在 filezilla 中,创建连接后出现此错误

Stato:          Risoluzione dell'indirizzo IP 4.tcp.ngrok.io in corso
Stato:          Connessione a 3.138.180.119:15947...
Stato:          Connessione stabilita, in attesa del messaggio di benvenuto...
Risposta:   220-Hello user!
Risposta:   220 Features: a .
Comando:    AUTH TLS
Risposta:   502 Command not supported
Comando:    AUTH SSL
Risposta:   504 Command parameter not supported
Stato:          Server non sicuro. Non supporta FTP su TLS.
Comando:    USER anonymous
Risposta:   530 log is not defined
Errore:         Impossibile collegarsi al server

有什么解决办法吗?

node.js ftp command-line-interface
1个回答
0
投票

对我来说,这是因为未定义被动配置,并且在我配置了 FTP 上的 TSL 之后。我使用的是 Azure VM,其中公共 IP 作为组件添加,被动连接尝试使用该 IP 连接到服务器,该服务器不是机器本身的网络列表。我能够按如下方式修复此配置被动连接配置,

const ftpServer = new FtpSrv({
  url: "0.0.0.0:21",
  pasv_url: "YOUR PUBLIC IP",
  pasv_min: 40000,
  pasv_max: 40100,
  tls: {
    key: fs.readFileSync(keyFile),
    cert: fs.readFileSync(certFile),
  },
});
© www.soinside.com 2019 - 2024. All rights reserved.