Node js can't upload files to FTP when deployed and running on production server

I’m using Node JS (12.13.0) and NPM (6.13.19) with basic-ftp. Everything works fine and I can upload files to the remote FTP (without SSL, my remote FTP doesn’t allow this) when I run the code on my development machine from localhost.

The production server is hosted on Digital Ocean (Ubuntu 18.04.3) I have tried to disable the firewall, because I thought this might be the reason to the problem. I used sudo ufw disable and just to make sure it’s disabled I check the current status with sudo ufw statuswhich returns Status: inactive.

This is my code

async function uploadImageToFtp(fileName, path) {
    const client = new ftp.Client()
    client.ftp.verbose = true
    try {
        await client.access({
            host: process.env.FTP_HOST,
            user: process.env.FTP_USER,
            password: process.env.FTP_PASSWORD,
            secure: false
        await client.uploadFrom(path, "images/bd/" + fileName)
    } catch (err) {

Response on production

Connected to EXTERNAL_IP_ADDRESS < 220 server ready - login please Login
security: No encryption
> USER username < 331 password required
> PASS ###

Again on localhost everything works and we get past this step and starts uploading the file(s) to the same server and credentials.

After this I never get any response, except for a timeout with Bad Gateway 502 from my request.

Same questions is posted and asked on SO:

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

It seems like that you haven’t configured any FTP service yet.

We do not provide any droplet images with FTP running by default as it is an inherently insecure protocol. SFTP is running on all new droplets on port 22 and can be accessed with your root login credentials using Filezilla. When logging in as root you will start out in the /root directory but will have access to access any directory you require.

You can also try to connect to your droplet via the terminal:

sftp root@yourIPaddress

You can check this article on how to setup vsftpd on your droplet.

If you want to connect from your droplet to any other FTP host, you can first try to make sure that the external FTP host is reachable and that ftp is running as well by using the telnet and the nmap commands from my previous reply.

Hope this helps.

Regards, Alex

Hi @alexdo, Thanks for your reply. Please see the details below.

netstat -plunta | grep 21
tcp        0    308       ESTABLISHED -                   

telnet DropletIP 21
Trying DropletIP...
telnet: Unable to connect to remote host: Connection refused

nmap DropletIP | grep 21
Starting Nmap 7.60 ( ) at 2019-11-21 09:27 UTC

DropletIP is my Droplet’s public IP.

Hello, @grumsendev

Can you check if the port is open and any ftp service is listening on it? You can do this by using telnet, nmap (externaly) and using netstat (internally)

  1. Using netstat

You need to access your server via ssh and execute the following command:

netstat -plunta | grep 21

You will see if any service is listening on port 21 (FTP)

  1. Using nmap or telnet
telnet DropletIP 21

nmap DropletIP | grep 21

Let me know what is the output of this commands.

Regards, Alex