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) {
console.log(err)
}
client.close()
}
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: https://stackoverflow.com/questions/58949317/node-js-cant-upload-files-to-ftp-when-deployed-and-running-on-production-server
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!
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)
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)
telnet DropletIP 21
nmap DropletIP | grep 21
Let me know what is the output of this commands.
Regards, Alex
Hi @alexdo, Thanks for your reply. Please see the details below.
netstat -plunta | grep 21
tcp 0 308 167.172.171.131:22 46.32.61.37:52185 ESTABLISHED -
–
telnet DropletIP 21
Trying DropletIP...
telnet: Unable to connect to remote host: Connection refused
–
nmap DropletIP | grep 21
Starting Nmap 7.60 ( https://nmap.org ) at 2019-11-21 09:27 UTC
DropletIP is my Droplet’s public IP.
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.