node-ftps-promise
Fork of node-ftps using available ES6 in node 4.2.1 and Promises
FTP, FTPS and SFTP client for node.js, mainly a lftp
wrapper.
Requirements
You need to have the executable lftp
installed on your computer.
LFTP Homepage
LFTP For Windows
Installation
npm install ftps
Usage
var FTPS = require('ftps');
var ftps = FTPS({
host: 'domain.com',
username: 'Test',
password: 'Test',
protocol: 'sftp',
port: 22,
escape: true,
retries: 2,
timeout: 10,
requiresPassword: true,
autoConfirm: true,
cwd: ''
});
ftps.cd('some_directory').addFile(__dirname + '/test.txt').then(console.log);
Some documentation
Here are some of the chainable functions :
ftps.ls()
ftps.pwd()
ftps.cd(directory)
ftps.cat(pathToRemoteFiles)
ftps.put(pathToLocalFile, [pathToRemoteFile])
ftps.get(pathToRemoteFile, [pathToLocalFile])
ftps.mv(from, to)
ftps.rm(file1, file2, ...)
ftps.rmdir(directory1, directory2, ...)
If you want to escape some arguments because you used "escape: false" in the options:
ftps.escapeshell('My folder');
Execute a command on the remote server:
ftps.raw('ls -l')
To see all available commands: LFTP Commands
For information, ls, pwd, ... rm are just some alias of raw() method.
Run the commands
ftps.exec().then(res => {
});
Also, take note that if a command fails it will not stop the next commands from executing, for example:
ftps.cd('non-existing-dir/').addFile('./test.txt').then(console.log);
Why?
Because I wantded to be able to compose it with promises and wanted methods to be first-class, so avoid the hassle of prototype.