Not able to connect to ftp server using filezilla through ngrok

86 views Asked by At

I am using ngrok to expose ftp server publically. When I am connecting to ftp server using file zilla client it is showing error which is "Server sent passive reply with unroutable address. Using server address instead."

Error which is showing in filezilla is as follows:

Status: Connecting to 3.6.122.107:13674... Status: Connection established, waiting for welcome message... Status: Insecure server, it does not support FTP over TLS. Status: Logged in Status: Retrieving directory listing... Status: Server sent passive reply with unroutable address. Using server address instead. Command: LIST Response: 425 No connection established Error: Failed to retrieve directory listing

Index.js file of my ftp server is as follows

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)
});



I am using ngrok to expose ftp server publically. When I am connecting to ftp server using file zilla client it is showing error which is "Server sent passive reply with unroutable address. when I directly cononect using filezilla it works but I want to know how to configure this ftp server so that I can connect to this server using filezilla through ngrok.

0

There are 0 answers