• Stars
    star
    1,128
  • Rank 41,074 (Top 0.9 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 13 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An FTP client module for node.js

Description

node-ftp is an FTP client module for node.js that provides an asynchronous interface for communicating with an FTP server.

Requirements

Install

npm install ftp

Examples

  • Get a directory listing of the current (remote) working directory:
  var Client = require('ftp');

  var c = new Client();
  c.on('ready', function() {
    c.list(function(err, list) {
      if (err) throw err;
      console.dir(list);
      c.end();
    });
  });
  // connect to localhost:21 as anonymous
  c.connect();
  • Download remote file 'foo.txt' and save it to the local file system:
  var Client = require('ftp');
  var fs = require('fs');

  var c = new Client();
  c.on('ready', function() {
    c.get('foo.txt', function(err, stream) {
      if (err) throw err;
      stream.once('close', function() { c.end(); });
      stream.pipe(fs.createWriteStream('foo.local-copy.txt'));
    });
  });
  // connect to localhost:21 as anonymous
  c.connect();
  • Upload local file 'foo.txt' to the server:
  var Client = require('ftp');
  var fs = require('fs');

  var c = new Client();
  c.on('ready', function() {
    c.put('foo.txt', 'foo.remote-copy.txt', function(err) {
      if (err) throw err;
      c.end();
    });
  });
  // connect to localhost:21 as anonymous
  c.connect();

API

Events

  • greeting(< string >msg) - Emitted after connection. msg is the text the server sent upon connection.

  • ready() - Emitted when connection and authentication were sucessful.

  • close(< boolean >hadErr) - Emitted when the connection has fully closed.

  • end() - Emitted when the connection has ended.

  • error(< Error >err) - Emitted when an error occurs. In case of protocol-level errors, err contains a 'code' property that references the related 3-digit FTP response code.

Methods

* Note: As with the 'error' event, any error objects passed to callbacks will have a 'code' property for protocol-level errors.

  • (constructor)() - Creates and returns a new FTP client instance.

  • connect(< object >config) - (void) - Connects to an FTP server. Valid config properties:

    • host - string - The hostname or IP address of the FTP server. Default: 'localhost'

    • port - integer - The port of the FTP server. Default: 21

    • secure - mixed - Set to true for both control and data connection encryption, 'control' for control connection encryption only, or 'implicit' for implicitly encrypted control connection (this mode is deprecated in modern times, but usually uses port 990) Default: false

    • secureOptions - object - Additional options to be passed to tls.connect(). Default: (none)

    • user - string - Username for authentication. Default: 'anonymous'

    • password - string - Password for authentication. Default: 'anonymous@'

    • connTimeout - integer - How long (in milliseconds) to wait for the control connection to be established. Default: 10000

    • pasvTimeout - integer - How long (in milliseconds) to wait for a PASV data connection to be established. Default: 10000

    • keepalive - integer - How often (in milliseconds) to send a 'dummy' (NOOP) command to keep the connection alive. Default: 10000

  • end() - (void) - Closes the connection to the server after any/all enqueued commands have been executed.

  • destroy() - (void) - Closes the connection to the server immediately.

Required "standard" commands (RFC 959)

  • list([< string >path, ][< boolean >useCompression, ]< function >callback) - (void) - Retrieves the directory listing of path. path defaults to the current working directory. useCompression defaults to false. callback has 2 parameters: < Error >err, < array >list. list is an array of objects with these properties:

    * type - _string_ - A single character denoting the entry type: 'd' for directory, '-' for file (or 'l' for symlink on **\*NIX only**).
    
    * name - _string_ - The name of the entry.
    
    * size - _string_ - The size of the entry in bytes.
    
    * date - _Date_ - The last modified date of the entry.
    
    * rights - _object_ - The various permissions for this entry **(*NIX only)**.
    
        * user - _string_ - An empty string or any combination of 'r', 'w', 'x'.
    
        * group - _string_ - An empty string or any combination of 'r', 'w', 'x'.
    
        * other - _string_ - An empty string or any combination of 'r', 'w', 'x'.
    
    * owner - _string_ - The user name or ID that this entry belongs to **(*NIX only)**.
    
    * group - _string_ - The group name or ID that this entry belongs to **(*NIX only)**.
    
    * target - _string_ - For symlink entries, this is the symlink's target **(*NIX only)**.
    
    * sticky - _boolean_ - True if the sticky bit is set for this entry **(*NIX only)**.
    
  • get(< string >path, [< boolean >useCompression, ]< function >callback) - (void) - Retrieves a file at path from the server. useCompression defaults to false. callback has 2 parameters: < Error >err, < ReadableStream >fileStream.

  • put(< mixed >input, < string >destPath, [< boolean >useCompression, ]< function >callback) - (void) - Sends data to the server to be stored as destPath. input can be a ReadableStream, a Buffer, or a path to a local file. useCompression defaults to false. callback has 1 parameter: < Error >err.

  • append(< mixed >input, < string >destPath, [< boolean >useCompression, ]< function >callback) - (void) - Same as put(), except if destPath already exists, it will be appended to instead of overwritten.

  • rename(< string >oldPath, < string >newPath, < function >callback) - (void) - Renames oldPath to newPath on the server. callback has 1 parameter: < Error >err.

  • logout(< function >callback) - (void) - Logout the user from the server. callback has 1 parameter: < Error >err.

  • delete(< string >path, < function >callback) - (void) - Deletes a file, path, on the server. callback has 1 parameter: < Error >err.

  • cwd(< string >path, < function >callback) - (void) - Changes the current working directory to path. callback has 2 parameters: < Error >err, < string >currentDir. Note: currentDir is only given if the server replies with the path in the response text.

  • abort(< function >callback) - (void) - Aborts the current data transfer (e.g. from get(), put(), or list()). callback has 1 parameter: < Error >err.

  • site(< string >command, < function >callback) - (void) - Sends command (e.g. 'CHMOD 755 foo', 'QUOTA') using SITE. callback has 3 parameters: < Error >err, < _string >responseText, < integer >responseCode.

  • status(< function >callback) - (void) - Retrieves human-readable information about the server's status. callback has 2 parameters: < Error >err, < string >status.

  • ascii(< function >callback) - (void) - Sets the transfer data type to ASCII. callback has 1 parameter: < Error >err.

  • binary(< function >callback) - (void) - Sets the transfer data type to binary (default at time of connection). callback has 1 parameter: < Error >err.

Optional "standard" commands (RFC 959)

  • mkdir(< string >path, [< boolean >recursive, ]< function >callback) - (void) - Creates a new directory, path, on the server. recursive is for enabling a 'mkdir -p' algorithm and defaults to false. callback has 1 parameter: < Error >err.

  • rmdir(< string >path, [< boolean >recursive, ]< function >callback) - (void) - Removes a directory, path, on the server. If recursive, this call will delete the contents of the directory if it is not empty. callback has 1 parameter: < Error >err.

  • cdup(< function >callback) - (void) - Changes the working directory to the parent of the current directory. callback has 1 parameter: < Error >err.

  • pwd(< function >callback) - (void) - Retrieves the current working directory. callback has 2 parameters: < Error >err, < string >cwd.

  • system(< function >callback) - (void) - Retrieves the server's operating system. callback has 2 parameters: < Error >err, < string >OS.

  • listSafe([< string >path, ][< boolean >useCompression, ]< function >callback) - (void) - Similar to list(), except the directory is temporarily changed to path to retrieve the directory listing. This is useful for servers that do not handle characters like spaces and quotes in directory names well for the LIST command. This function is "optional" because it relies on pwd() being available.

Extended commands (RFC 3659)

  • size(< string >path, < function >callback) - (void) - Retrieves the size of path. callback has 2 parameters: < Error >err, < integer >numBytes.

  • lastMod(< string >path, < function >callback) - (void) - Retrieves the last modified date and time for path. callback has 2 parameters: < Error >err, < Date >lastModified.

  • restart(< integer >byteOffset, < function >callback) - (void) - Sets the file byte offset for the next file transfer action (get/put) to byteOffset. callback has 1 parameter: < Error >err.

More Repositories

1

ssh2

SSH2 client and server modules written in pure JavaScript for node.js
JavaScript
5,493
star
2

busboy

A streaming parser for HTML form data for node.js
JavaScript
2,825
star
3

node-imap

An IMAP client module for node.js.
JavaScript
2,149
star
4

mmmagic

An async libmagic binding for node.js for detecting content types by data inspection
C++
617
star
5

node-mariasql

A node.js binding to MariaDB's non-blocking (MySQL-compatible) client library
C++
485
star
6

socksv5

SOCKS protocol version 5 server and client implementations for node.js
JavaScript
400
star
7

node-ncurses

An ncurses binding for node.js
C++
385
star
8

cap

A cross-platform binding for performing packet capturing with node.js
JavaScript
360
star
9

ssh2-streams

SSH2 and SFTP client/server protocol streams for node.js
JavaScript
204
star
10

node-xxhash

An xxhash binding for node.js
C++
193
star
11

sipster

A pjsip/pjsua2 binding for node.js
C++
190
star
12

dicer

A very fast streaming multipart parser for node.js
JavaScript
186
star
13

httpolyglot

Serve http and https connections over the same port with node.js
JavaScript
181
star
14

connect-busboy

Connect middleware for busboy
JavaScript
155
star
15

node-asterisk

An Asterisk module for node.js
JavaScript
96
star
16

spellcheck

An async hunspell binding for node.js
C++
82
star
17

node-nntp

An NNTP client module for node.js
JavaScript
74
star
18

streamsearch

Streaming Boyer-Moore-Horspool searching for node.js
JavaScript
69
star
19

node-rtp

An RTP module in pure JavaScript for node.js
JavaScript
59
star
20

node-oscar

An OSCAR protocol client module for node.js
JavaScript
54
star
21

cpu-features

A simple node.js binding to Google's cpu_features library for obtaining information about installed CPU(s)
C++
40
star
22

node-pcre

A pcre binding for node.js
C++
39
star
23

esqlite

An SQLite binding for node.js with built-in encryption, focused on simplicity and (async) performance
C++
36
star
24

base91.js

basE91 encoding/decoding for node.js and browsers
JavaScript
31
star
25

bellhop

A node.js module that exposes streams for doing Pubsub and RPC.
JavaScript
28
star
26

ssh-repl

SSH into your node.js process and access a REPL
JavaScript
26
star
27

groan

A PHP session file parser written in JavaScript
JavaScript
24
star
28

paclient

PulseAudio client written in pure JavaScript for node.js
JavaScript
23
star
29

pg2

A PostgreSQL driver for node.js that focuses on performance
JavaScript
21
star
30

pmq

A node.js addon for using POSIX message queues
C++
19
star
31

grappler

A minimalistic server for "comet" connections in Node.js.
JavaScript
19
star
32

reformed

A high-level form field handling and validation module for busboy
JavaScript
18
star
33

zup

A simple, fast template engine for node.js
JavaScript
15
star
34

express-optimized

A minimal, optimized version of Express
JavaScript
13
star
35

xfer

Simple binary TLV reader/writer for node.js
JavaScript
12
star
36

youknow

A realtime, multiplayer card game for node.js that supports multiple frontends
JavaScript
11
star
37

odroid-c2-minimal-debian-ubuntu

Fork of various scripts to setup a minimal debian/ubuntu installation for the odroid c2
Shell
8
star
38

print

A node.js module for communicating with printers
JavaScript
7
star
39

filebounce

A server for bouncing files from point A to point B
JavaScript
7
star
40

node-poormansmysql

MySQL driver module for node.js that executes queries using the mysql command-line client.
JavaScript
7
star
41

buffy

Access and manipulate multiple node.js Buffers as if they were one continuous Buffer
JavaScript
6
star
42

nodebench

Node.js Benchmark Results
HTML
6
star
43

xsys

A node.js binding to useful system-level functions
C++
5
star
44

speaky

A binding to the SVOX Pico engine (libttspico) for performing text-to-speech
C++
4
star
45

lrused

An LRU cache for node.js
JavaScript
4
star
46

conveyor

Feed multiple node.js streams sequentially into one stream
JavaScript
3
star
47

benchd

Benchmark JavaScript code across different node.js/io.js versions from the browser
JavaScript
3
star
48

beepjs

A BEEP protocol implementation for node.js
JavaScript
3
star
49

vermal

A VRML 1.0 push parser for node.js
JavaScript
2
star
50

datatables.sortpriorities

Display column sort orders in your Datatables table headers
JavaScript
1
star
51

build-addons

Build node.js addon binaries for releases using Github Actions
JavaScript
1
star
52

buildcheck

Build environment checking (a la autoconf) for node.js
JavaScript
1
star