I am trying to containerise an ftp server NodeJS application. It works fine when I run it with npm but it does not respond when I run it inside of a container.
This is the node app: The src/index.js file
const FtpSvr = require ( 'ftp-srv' );
const hostname = '127.0.0.1';
const port = 21;
const ftpServer = new FtpSvr ({
url:`ftp://${hostname}:${port}`,
anonymous:true
} );
ftpServer.on('login', ({connection, username, password}, resolve, reject) =>
{
resolve({root : "./"})
connection.on('STOR', (error, fileName) => {
console.log("STOR")
});
});
ftpServer.on ( 'client-error', (connection, context, error) =>
{
console.log ( `error: ${error}` );
});
ftpServer.listen().then(() => {console.log(`Server running at http://${hostname}:${port}/`);});
my package.json file
{
"name": "ftp-server",
"version": "1.0.0",
"description": "FTP server to receive images from cameras and save them on Azure Blob storage",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node src/index.js"
},
"author": "Rakshak",
"license": "ISC",
"dependencies": {
"ftp-srv": "4.3.4"
}
}
my docker file
FROM node:12
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . .
EXPOSE 20-21
EXPOSE 65500-65515
CMD ["npm", "start"]
I am testing the FTP server using FileZilla. When I run the server using npm start and connect using FileZilla
Connecting to 127.0.0.1:5000...
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: Directory listing of "/" successful
I am using this command to build the docker image
docker build -t rrakshak/ftp-demo .
And I am using this to run the docker
docker run -p 5000:5000 rrakshak/ftp-demo:latest
This is the message on the FileZilla console
Connecting to 127.0.0.1:5000...
Status: Connection established, waiting for welcome message...
Error: Connection closed by server
Error: Could not connect to server
Status: Waiting to retry...
Status: Connecting to 127.0.0.1:5000...
Status: Connection established, waiting for welcome message...
Error: Connection closed by server
Error: Could not connect to server
It looks like when the server is running inside of a container the FileZilla is able to connect but is not receiving the file listing response it expects.
------------Update-----------------------
setting the host to 0.0.0. give me a new set of messages on Filezilla
Status: Connecting to 127.0.0.1:21...
Status: Connection established, waiting for welcome message...
Status: Insecure server, it does not support FTP over TLS.
Status: Logged in
Status: Retrieving directory listing...
Command: PWD
Response: 257 "/"
Command: TYPE I
Response: 200 Switch to "binary" transfer mode.
Command: PASV
Response: 502 Command not supported
Command: PORT 127,0,0,1,231,209
Response: 500 The given address is not yours
Error: Failed to retrieve directory listing
Why does my app work when I run it in node but not when I containerise it?