Détail du package

ftp-deploy

simonh100031.6kMIT2.4.7

Ftp a folder from your local disk to an ftp destination

ftp, deploy

readme

ftp-deploy

A Node.js package to help with deploying code. Ftp a folder from your local disk to a remote ftp destination. Does not delete from destination directory.

Installation

npm install --save-dev ftp-deploy

Usage

The most basic usage:

const FtpDeploy = require("ftp-deploy");
const ftpDeploy = new FtpDeploy();

const config = {
    user: "user",
    // Password optional, prompted if none given
    password: "password",
    host: "ftp.someserver.com",
    port: 21,
    localRoot: __dirname + "/local-folder",
    remoteRoot: "/public_html/remote-folder/",
    // include: ["*", "**/*"],      // this would upload everything except dot files
    include: ["*.php", "dist/*", ".*"],
    // e.g. exclude sourcemaps, and ALL files in node_modules (including dot files)
    exclude: [
        "dist/**/*.map",
        "node_modules/**",
        "node_modules/**/.*",
        ".git/**",
    ],
    // delete ALL existing files at destination before uploading, if true
    deleteRemote: false,
    // Passive mode is forced (EPSV command is not sent)
    forcePasv: true,
    // use sftp or ftp
    sftp: false,
};

ftpDeploy
    .deploy(config)
    .then((res) => console.log("finished:", res))
    .catch((err) => console.log(err));

Note:

  • in version 2 the config file expects a field of user rather than username in 1.x.
  • The config file is passed as-is to Promise-FTP.
  • I create a file - e.g. deploy.js - in the root of my source code and add a script to its package.json so that I can npm run deploy.
"scripts": {
    "deploy": "node deploy"
},
  • You can use callback instead of promise.
// use with callback
ftpDeploy.deploy(config, function (err, res) {
    if (err) console.log(err);
    else console.log("finished:", res);
});

Configuration include and exclude

These are lists of minimatch globs. ftp-deploy works by checking for each file in your source directory, whether it is included by one of the include patterns and whether it is NOT excluded by one of the exclude patterns. In other words:

  • include: all files that match will be uploaded. Note that a [ ] matches nothing
  • exclude: if a file matches the include pattern a subset may nonetheless be excluded

Events

ftp-deploy reports to clients using events. To get the output you need to implement watchers for "uploading", "uploaded" and "log":

ftpDeploy.on("uploading", function (data) {
    console.log(data.totalFilesCount); // total file count being transferred
    console.log(data.transferredFileCount); // number of files transferred
    console.log(data.filename); // partial path with filename being uploaded
});
ftpDeploy.on("uploaded", function (data) {
    console.log(data); // same data as uploading event
});
ftpDeploy.on("log", function (data) {
    console.log(data); // same data as uploading event
});
ftpDeploy.on("upload-error", function (data) {
    console.log(data.err); // data will also include filename, relativePath, and other goodies
});

Testing

A script to run a simple ftp server (using ftp-srv) is included, together with a test directory.

To use open a console to run the ftp server:

cd test
npm run server

and then in another console run the tests:

npm test

Release

npm version patch
git commit -m 'bump'
npm publish
git push origin vx.y.z

ToDo

  • re-enable continueOnError
  • update newer files only (PR welcome)

changelog

Changelog

2.4.0

- Add support for SFTP - thanks @der-On

2.3.7

- tidier errors when connect fails

2.3.4-6

- update deps

2.3.3

- If delete does not work, try to continue anyway

2.3.2

- Require node 8.0

2.3.1

- Fix a bug some experienced uploaded to "/"

2.3.0

- Return result of process at end of run

2.2.1

- Bugfix: transfered file count

2.2.0

- remove console logs in favour of 'log' events

2.1.1

- AFix a bug for windows users

2.1.0

- Add delete destination before commencing uploads

2.0.0

- complete rewrite using promises
- switch from jsftp to ftp-srv
- breaks continueOnError
- config must now include an include field with non-empty value. E.g. use ['*', '**/*'] for all files
- format using prettier
- adds tests

1.2.0

- Adds an optional config.include which supersedes any exclusion rules.
- Linting code cleanup via xo style/tool

1.1.0

- Updated dependencies

1.0.0

- refactored for (hopefully) easier to understand code
- brought jsftp to 1.3.x, async to 0.9.x
- removed relative path from uploading/uploaded event data. (filename contains file name and partial path)

0.7.0

- added prompting user for FTP password if none given in config

0.6.0

- added optional ```continueOnError``` config. When set to true, ftp-deploy continues to upload files after a failed put. When not specified or set to false, the ```.deploy()``` callback is called immediately after a failed put.
- added ```upload-error``` event
- removed ```stopOnError``` config setting in preference of ```continueOnError```

0.5.0

- upgraded jsftp from 0.6.x to 1.2.x
- Added ```stopOnError``` to configuration.
- added ```error``` event.
- deprecated paralleluploads config setting (no longer supported by jsftp)

0.4.0

- uploading and uploaded events emit data instead of a relative file path.

0.3.0

- New config setting ```exclude``` can be used to exclude folders/files from the ftp deploy process

0.2.0

- Requiring ftp-deploy returns the FtpDeploy object, and you will need to instantiate is separately on your own.
- New config setting ```paralleluploads```: sets number of  parallelUploads (within a specific folder)
- ftpDeploy instance has properties ```transferred``` and ```total```. Useful for determining progress based on file count.