无法通过 ngrok 使用 filezilla 连接到 ftp 服务器

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

我正在使用 ngrok 公开公开 ftp 服务器。当我使用 file zilla 客户端连接到 ftp 服务器时,它显示错误“服务器发送了带有不可路由地址的被动回复。请改用服务器地址。”

filezilla 中显示的错误如下:

状态:正在连接到 3.6.122.107:13674... 状态:连接已建立,正在等待欢迎消息... 状态:不安全的服务器,不支持 FTP over TLS。 状态: 已登录 状态:正在检索目录列表... 状态:服务器发送了带有不可路由地址的被动回复。使用服务器地址代替。 命令:列表 响应:425 未建立连接 错误:无法检索目录列表

我的ftp服务器的Index.js文件如下

const { FtpSrv, ftpErrors } = require('ftp-srv');
const path = require('path')
const fs = require('fs')
const errors = require('ftp-srv/src/errors');


const port = 21;
const ftpServer = new FtpSrv({
    pasv_url: "tcp://0.tcp.in.ngrok.io:13674",
    url: 'ftp://127.0.0.1:' + port,
    anonymous: false,


});


ftpServer.on('login', ({ connection, username, password }, resolve, reject) => {

    //user authentication
    console.log(`Client connected: ${connection.ip}, User: ${username}`);

    // console.log("login", username, password);
    //ftp://falana:[email protected]:15064/

    //*CON#CFUP#0.tcp.ngrok.io#15064#falana#falana#55L_PRDT_V1_0_1.pac#


    //if user is anonymous 
    if (username == 'anonymous') {
        console.log(`Authentication failed for anonymous user`);
        return reject(new errors.GeneralError('Invalid User : Anonymous User', 401));

    }


    if (username === 'falana' && password === 'falana') {

        // Set the root directory for the authenticated user
        const userRoot = path.join(__dirname, 'ftp-root', username);

        // Check if the user's root directory exists, create if not
        if (!fs.existsSync(userRoot)) {
            fs.mkdirSync(userRoot, { recursive: true });
        }

        resolve({ root: userRoot });

    } else {
        return reject(new errors.GeneralError('Invalid Username or Password', 401));

    }


    // Event handler when a file is requested for download (RETR command)
    connection.on('RETR', (error, filePath) => {

        if (error) {
            console.log(`Error while downloading file. Error: ${error}`)
            return;
        }
        // console.log(filePath);
        console.log('file downloaded successfully...', filePath)

    });



    // Event handler when a file is requested for upload (STOR command)
    connection.on('STOR', (error, filePath) => {

        if (error) {
            console.log(`Error while uploading file. Error: ${error}`)
            return;
        }
        // console.log(filePath);
        console.log('file uploaded successfully...', filePath)

    });


    //event handler for file rename event
    connection.on('RNTO', (error, fileName) => {
        if (error) {
            console.log(`Error while renaming file. Error: ${error}`)
            return;
        }

        console.log('file renamed successfully...', fileName)
    });

});


//Occurs when an error arises in the FTP server
ftpServer.on('server-error', ({ error }) => {
    console.log(error)
});


//Occurs when a client disconnects
ftpServer.on('disconnect', ({ connection, id, newConnectionCount }) => {
    console.log('client disconnected', 'id', ':', id)
    console.log('new connection count on client disconnected ', ': ', newConnectionCount)
});


//occurs whenn a client connects
ftpServer.on('connect', ({ connection, id, newConnectionCount }) => {
    console.log('new connection count on new client connection ', ': ', newConnectionCount)
})


//Occurs when the FTP server has been closed
ftpServer.on('closed', ({ }) => {
    console.log('ftp server closed')
});


ftpServer.listen().then(() => {
    console.log(`Ftp server is listening on port ${port}...`)
}).catch((err) => {
    console.log(err)
});



我正在使用 ngrok 公开公开 ftp 服务器。当我使用 file zilla 客户端连接到 ftp 服务器时,它显示错误“服务器发送了带有不可路由地址的被动回复。 当我直接使用 filezilla 连接时它可以工作,但我想知道如何配置此 ftp 服务器,以便我可以通过 ngrok 使用 filezilla 连接到此服务器。

javascript node.js ftp ftp-client filezilla
1个回答
0
投票

你能解决这个问题吗?我想做和你一样的事情,但我收到了同样的错误消息:

Mon May 13 19:20:55 2024 [pid 1981366] CONNECT: Client "::1"
Mon May 13 19:21:03 2024 [pid 1981365] [jaliaga] FAIL LOGIN: Client "::1"
© www.soinside.com 2019 - 2024. All rights reserved.