Skip to content

Example node.js ftp server?

I need to create a node.js app that connects to this ftp server and downloads files from this directory:

I’ve tried following the ftp npm package docs but I feel like I am doing something horribly wrong:

import Client from "ftp";


const c = new Client();

c.on("ready", function () {
        (error, stream) => {
            if (error) throw error;
            console.log(`stream`, stream);
            stream.once("close", function () {

// connect to localhost:21 as anonymous

When I run npm run dev with nodemon I get:

Error: connect ECONNREFUSED
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
[nodemon] app crashed - waiting for file changes before starting...

Can someone please help? I’m completely stumped.

Is it possible if someone could show me a small example of how I can connect to this remote ftp server?



There are a few points :

  • You’re connecting to the local ftp with c.connect();. You need to connect to to download files from there.
  • This path cors/rinex/2021/143/nynb is a directory on the remote host. c.get doesn’t work, you need to list all files in the directory then download them 1 by 1.

The code below connect to the remote server and list all files in the directory

const Client = require('ftp');
const fs = require("fs");
const c = new Client();

c.on('ready', function () {
    c.list( "/cors/rinex/2021/143/nynb", function (err, list) {
        if (err) throw err;

    host: "",