node-sftps
SFTP client for node.js, mainly a sftp
wrapper.
This is a fork of the ftps
module. This fork only supports sftp, and uses the sftp
command instead of lftp
. This allows you to specify ssh-specific options such as private key file.
Requirements
You need to have the executable sftp
installed on your computer.
If you are using password authentication, you also need to have the sshpass
utility installed.
Installation
npm install sftps
Usage
var SFTPS = require('sftps');
var sftp = new SFTPS({
host: 'domain.com',
username: 'Test',
password: 'Test',
port: 22
});
sftp.cd('myDir').addFile(__dirname + '/test.txt').exec(console.log);
Some documentation
Here are chainable fonctions :
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, ...)
Execute a command on the remote server:
sftp.raw('ls -l')
For information, ls, pwd, ... rm are just some alias of raw() method.
Run the commands !
sftp.exec(function (err, res) {
});
Also, take note that if a command fails it will not stop the next commands from executing, for example:
sftp.cd('non-existing-dir/').affFile('./test.txt').exec(console.log);
Why?
Just because I didn't found sftp and ftps module in node.js, it's pretty dirty to spawn sftp
command, but sorry, it does the work for me, maybe for you too :)
Ah and sorry for tests, it's a hack, so I just do some manual tests.