to-ssh

0.5.1 • Public • Published

Task-Oriented SSH

Description

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.

Requirements

  • node.js - v0.8.7 or newer ([@todo] - check it - may run on even lower versions)

Features

  • 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

Installation

$ npm install to-ssh

Examples & API

Initialize

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 encrypted privateKey; default: null

NOTE: You always have to specify either privateKey or password!

var ssh = new ToSSH({
    host: "http://github.com",
    privateKey: fs.readFileSync({{ path-to-your-key }})
});

ssh.connect([callback])

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!"
    }
});

ssh.addTask(command, [callback])

Adds the tasks to queue and executes if possible.

  • command {string} - command to be executed
  • callback {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"
    }
});

ssh.disconnect()

Disconnects from the host.

ssh.disconnect();

Package Sidebar

Install

npm i to-ssh

Weekly Downloads

0

Version

0.5.1

License

MIT

Last publish

Collaborators

  • biphobe