Node.js FTP Client

0.3.10 · abandoned · verified Tue Apr 21

This is an FTP client module for Node.js, providing an asynchronous interface for communicating with FTP servers. The latest stable version, 0.3.10, was last published in February 2016, making it a very old and unmaintained package. It primarily supports older Node.js versions (>=0.8.0) and exclusively uses CommonJS modules. It offers core FTP operations such as listing directories, downloading, and uploading files through an event-driven API. While it was a foundational FTP client in early Node.js ecosystems, it lacks modern features, security updates, and active maintenance compared to newer, actively developed alternatives like `basic-ftp` or `promise-ftp`.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates connecting to an FTP server, downloading a specified remote file, and saving it to the local filesystem using streams. It includes error handling and utilizes environment variables for connection configuration.

const Client = require('ftp');
const fs = require('fs');

const FTP_HOST = process.env.FTP_HOST ?? 'localhost';
const FTP_PORT = parseInt(process.env.FTP_PORT ?? '21', 10);
const FTP_USER = process.env.FTP_USER ?? 'anonymous';
const FTP_PASSWORD = process.env.FTP_PASSWORD ?? 'anonymous@';
const REMOTE_FILE = process.env.REMOTE_FILE ?? 'remote-file.txt';
const LOCAL_COPY_FILE = process.env.LOCAL_COPY_FILE ?? 'local-copy.txt';

const c = new Client();
c.on('ready', function() {
  console.log(`Connected to ${FTP_HOST}:${FTP_PORT}. Attempting to download ${REMOTE_FILE}...`);
  c.get(REMOTE_FILE, function(err, stream) {
    if (err) {
      console.error('Error downloading file:', err.message, err.code ? `(Code: ${err.code})` : '');
      c.end();
      return;
    }
    stream.once('close', function() {
      console.log(`Successfully downloaded ${REMOTE_FILE} to ${LOCAL_COPY_FILE}.`);
      c.end();
    });
    stream.pipe(fs.createWriteStream(LOCAL_COPY_FILE));
  });
});

c.on('error', function(err) {
  console.error('FTP Client Error:', err.message, err.code ? `(Code: ${err.code})` : '');
});

c.on('end', function() {
  console.log('FTP connection ended.');
});

c.on('close', function(hadErr) {
  console.log('FTP connection closed. Had error:', hadErr);
});

c.connect({
  host: FTP_HOST,
  port: FTP_PORT,
  user: FTP_USER,
  password: FTP_PASSWORD,
  secure: false // Set to 'true' or 'control' for FTPS, 'implicit' for implicit FTPS (deprecated)
});

view raw JSON →