noodny / node-ftp-client

MIT License
64 stars 32 forks source link

Description

node-ftp-client is a wrapper for the popular FTP client module for node.js - node-ftp, which provides an easy way of manipulating FTP transfers.

Requirements

Dependencies

Installation

npm install ftp-client

Usage

Initialization

To crate an instance of the wrapper use the following code:

var ftpClient = require('ftp-client'),
client = new ftpClient(config, options);

where config contains the ftp server configuration (these are the default values):

{
    host: 'localhost',
    port: 21,
    user: 'anonymous',
    password: 'anonymous@'
}

and the options object may contain the following keys:

Connecting

After creating the new object you have to manually connect to the server by using the connect method:

client.connect(callback);

And passing the callback which should be executed when the client is ready.

Methods

Examples

In this example we connect to a server, and simultaneously upload all files from the test directory, overwriting only older files found on the server, and download files from /public_html/test directory.

var ftpClient = require('./lib/client.js'),
    config = {
        host: 'localhost',
        port: 21,
        user: 'anonymous',
        password: 'anonymous@'
    },
    options = {
        logging: 'basic'
    },
    client = new ftpClient(config, options);

client.connect(function () {

    client.upload(['test/**'], '/public_html/test', {
        baseDir: 'test',
        overwrite: 'older'
    }, function (result) {
        console.log(result);
    });

    client.download('/public_html/test2', 'test2/', {
        overwrite: 'all'
    }, function (result) {
        console.log(result);
    });

});

TODO