Simple and easy to use SSH2 wrapper for node.js.
Why task-oriented? Because each command you want to invoke is being added to the queue as task to run - it's for the sole purpose of giving you the ability to manipulate concurrency.
You can add 5 tasks to queue and run them all in the same time or run them one by one. It's up to you.
- node.js - v0.8.7 or newer ([@todo] - check it - may run on even lower versions)
- Handles multiple connections to different hosts in the same time
- Can queue requests or send them in parallel
- Runs callbacks asynchronously
- Easy to implement, use and maintain
$ npm install to-ssh
var ToSSH = require('to-ssh');
var ssh = new ToSSH(options);
options
{object} - required - object with options necessary to establish connection- options.
host
{string} - required - hostname - options.
username
{string} - optional - username; default: "root" - options.
privateKey
{string} - optional - private key or path to your private key; default: null - options.
port
{number} - optional - port; default: 22 - options.
conecurrency
{number} - optional - max number of concurrent connections to the host; default: 1 - options.
password
{string} - optional - password; default: null - options.
passphrase
{string} - optional - password to the encryptedprivateKey
; default: null
- options.
NOTE: You always have to specify either
privateKey
orpassword
!
var ssh = new ToSSH({
host: "http://github.com",
privateKey: fs.readFileSync({{ path-to-your-key }})
});
Connects to the host specified in options.
callback
{function} - callback to be invoked on connection success/error. If an error occurs while connecting an {string}error
will be passed to the callback
ssh.connect(function(error) {
if(!error) {
console.log("Connected!"); // -> "Connected!"
}
});
Adds the tasks to queue and executes if possible.
command
{string} - command to be executedcallback
{function} - callback to be invoked after command's execution. Two parameters which will contain the output will be passed to the function:stdout
,stderr
, both of the {string} type
ssh.addTask('whoami', function(stdout, stderr) {
if(!stderr) {
console.log(stdout); // -> "root"
}
});
Disconnects from the host.
ssh.disconnect();