0.0.2 • Published 9 years ago

ssh.js v0.0.2

Weekly downloads
5
License
MIT
Repository
github
Last release
9 years ago

ssh.js

ES7 SSH2 client.

ES7 Stage Build Status Dependency Status DevDependency Status

This project is currently under development by @MarkTiedemann.

The idea is to create a simple-to-use ES7 SSH2 client using babel.

Installation

npm install ssh.js --save

Quickstart

const Connection = require('ssh.js').Connection;

const options = {
   host: 'example.com',
   username: 'whoami',
   password: 'noidea'
};

let connection = new Connection(options);

try {

   await connection.open();
   console.log('Connection opened!');

   let whoami = await connection.execute('whoami');
   console.log('whoami = ' + whoami);

} catch (error) {
   console.log('An error occured!');
   console.log(error);

} finally {
   connection.close();
   console.log('Connection closed!');
}

API

Class Connection

constructor(options)

  • options: Object
    • host: String (default value: localhost)
    • port: Number (default value: 22)
    • username: String (default value: root)
    • password: string

Example:

let connection = new Connection({
   host: 'example.com',
   port: 22,
   username: 'whoami',
   password: 'noidea'
});

async function open()

Opens the connection or throws an error.

Example:

await connection.open();

async function execute(command)

  • command: String

Returns the result of the executed command as a String or throws an error.

Example:

let whoami = await connection.execute('whoami');

function close()

Closes this connection immediately.

Example:

connection.close();

Notes

Please note that you shouldn't use this module without a transpiler such as babel. This is because await and async are experimental ES7 features. Furthermore, please note that await is only usable from within an async function. You may use it, for example, from within an IIFE:

require("babel/register");

(async function() {

  // 'await' your ES7 code here

})();

License

The MIT License (MIT) as found in LICENSE.md.

Made with :heart:.

0.0.2

9 years ago

0.0.1

9 years ago