npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

js-ftp-library

v1.0.4

Published

A lightweight Node.js FTP server library built from scratch. Fully compliant with RFC 959, it supports custom configurations, directory listings, authentication, and more. Perfect for developers needing a robust FTP server for testing, development, or lig

Downloads

6

Readme

FTP Library

A lightweight FTP server library for Node.js. Fully compliant with RFC 959, this library is designed to be fast, reliable, and customizable. It is ideal for developers needing an FTP server for development, testing, or lightweight production use.

Features

  • Simple API for creating FTP servers.
  • Customizable port, host, and root directory settings.
  • Built-in authentication and directory listing support.
  • Lightweight, fast, and easy to extend.
  • Newly Added Commands: CWD, MKD, RMD, STAT, and HELP for enhanced functionality.

Installation

npm install js-ftp-server

Usage

const { FTPServer } = require('js-ftp-server');

const server = new FTPServer({ port: 2121 });
server.start();

Examples

1. Basic Server Setup

const { FTPServer } = require('ftp-library');

const server = new FTPServer({ port: 2121 });
server.start();

2. Custom Port and Host

const { FTPServer } = require('ftp-library');

const server = new FTPServer({ port: 2121, host: '127.0.0.1' });
server.start();

3. Anonymous Access

const { FTPServer } = require('ftp-library');

const server = new FTPServer({ allowAnonymous: true });
server.start();

4. Custom Root Directory

const { FTPServer } = require('ftp-library');

const server = new FTPServer({ rootDir: '/var/ftp' });
server.start();

5. User Authentication

const { FTPServer } = require('ftp-library');
const { validateCredentials } = require('./src/utils');

const server = new FTPServer();

server.handleConnection = (socket) => {
  socket.write('220 Welcome to the custom FTP server\r\n');
  socket.on('data', (data) => {
    const command = data.toString().trim();
    if (command.startsWith('USER admin') && validateCredentials('admin', 'password')) {
      socket.write('230 User logged in, proceed\r\n');
    } else {
      socket.write('530 Login incorrect\r\n');
    }
  });
};

server.start();

6. File Upload

const { FTPServer } = require('ftp-library');
const fs = require('fs');
const path = require('path');

const server = new FTPServer();

server.handleConnection = (socket) => {
  socket.on('data', (data) => {
    const command = data.toString().trim();
    if (command.startsWith('STOR')) {
      const fileName = command.split(' ')[1];
      const writeStream = fs.createWriteStream(path.join(server.rootDir, fileName));
      socket.pipe(writeStream);
      socket.write('226 Transfer complete\r\n');
    }
  });
};

server.start();

7. File Download

const { FTPServer } = require('ftp-library');
const fs = require('fs');
const path = require('path');

const server = new FTPServer();

server.handleConnection = (socket) => {
  socket.on('data', (data) => {
    const command = data.toString().trim();
    if (command.startsWith('RETR')) {
      const fileName = command.split(' ')[1];
      const readStream = fs.createReadStream(path.join(server.rootDir, fileName));
      readStream.pipe(socket);
      socket.write('226 Transfer complete\r\n');
    }
  });
};

server.start();

8. Passive Mode Support

const { FTPServer } = require('ftp-library');

const server = new FTPServer();

server.handleConnection = (socket) => {
  socket.on('data', (data) => {
    const command = data.toString().trim();
    if (command.startsWith('PASV')) {
      socket.write('227 Entering Passive Mode (127,0,0,1,192,168)\r\n');
    }
  });
};

server.start();

9. Logging Commands

const { FTPServer } = require('ftp-library');

const server = new FTPServer();

server.handleConnection = (socket) => {
  socket.on('data', (data) => {
    console.log(`Command received: ${data.toString().trim()}`);
    socket.write('502 Command not implemented\r\n');
  });
};

server.start();

10. Configurable Welcome Message

const { FTPServer } = require('ftp-library');

const server = new FTPServer();

server.handleConnection = (socket) => {
  socket.write('220 Welcome to My Custom FTP Server\r\n');
};

server.start();

11. Multiple Connections

const { FTPServer } = require('ftp-library');

const server = new FTPServer();

server.handleConnection = (socket) => {
  console.log('New connection established');
  socket.write('220 Ready\r\n');
};

server.start();

12. Rename File

const { FTPServer } = require('ftp-library');
const fs = require('fs');

const server = new FTPServer();

server.handleConnection = (socket) => {
  socket.on('data', (data) => {
    const command = data.toString().trim();
    if (command.startsWith('RNFR')) {
      const oldName = command.split(' ')[1];
      socket.once('data', (newData) => {
        const newName = newData.toString().trim().split(' ')[1];
        fs.renameSync(oldName, newName);
        socket.write('250 File renamed\r\n');
      });
    }
  });
};

server.start();

13. Delete File

const { FTPServer } = require('ftp-library');
const fs = require('fs');

const server = new FTPServer();

server.handleConnection = (socket) => {
  socket.on('data', (data) => {
    const command = data.toString().trim();
    if (command.startsWith('DELE')) {
      const fileName = command.split(' ')[1];
      fs.unlinkSync(fileName);
      socket.write('250 File deleted\r\n');
    }
  });
};

server.start();

14. Custom Command Implementation

const { FTPServer } = require('ftp-library');

const server = new FTPServer();

server.handleConnection = (socket) => {
  socket.on('data', (data) => {
    const command = data.toString().trim();
    if (command === 'MYCMD') {
      socket.write('200 Custom command executed\r\n');
    }
  });
};

server.start();

15. Advanced Logging

const { FTPServer } = require('ftp-library');
const fs = require('fs');

const logStream = fs.createWriteStream('./ftp-commands.log', { flags: 'a' });

const server = new FTPServer();

server.handleConnection = (socket) => {
  socket.on('data', (data) => {
    const command = data.toString().trim();
    logStream.write(`${new Date().toISOString()} - ${command}\n`);
    socket.write('502 Command not implemented\r\n');
  });
};

server.start();

License

MIT