Socket
Socket
Sign inDemoInstall

hussh

Package Overview
Dependencies
3
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hussh

SSH2 wrapper


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Install size
1.58 MB
Created
Weekly downloads
 

Readme

Source

HuSSH

HuSSH is a simple wrapper for ssh2 with only a few simple features:

  • Connects when you give it work to do
  • Always passes ENV vars (by prepending them to commands)
  • Simplified interface for uploading, downloading
  • Simplified methods for command execution:
    • buffering stdout/stderr
    • just waiting for exit code
  • Optionally logs activity to a local file
  • Tell the dog

If you need anything more complex than file upload/download and command execution, use ssh2 directly. If you don't need/want very simplified commands, use ssh2.

var hussh = require("hussh")
var client = hussh({
  host: "example.com",
  username: "foo",
  privateKey: require("fs").readFileSync("./my-secret.key")
}, {encoding: "utf-8"});

// upload a string to a remote file
client.uploadString("text for my file", "remote-file.txt", function(err){
  if ( ! err ) {
    // file contents uploaded
  }
});

// execute a command and save all buffered output
client.execBuffer("env", {MYENVVAR: "myenv-value"}, function(err, result){
  if ( ! err ) {
    // command exit status is 0, access result.stdout and result.stderr here
  }
  else {
    // command had non-zero exit status... see what happened
    console.error(err.message)
  }
});

Instantiation

var client = hussh(sshOptions, moreOptions);
  • sshOptions: these are passed directly to ssh2.connect
    • username: if not set, will be set according to precedence:
      • moreOptions.username
      • process.env.USER
      • "root"
    • host: if not set, will be set according to precedence:
      • moreOptions.hostname
      • moreOptions.host
      • "localhost"
    • All other options (such as privateKey) check ssh2 docs.
  • moreOptions: these only affect hussh, not ssh2 (except as noted above)
    • env: ENV vars to include for all further commands
    • encoding: sets encoding for local log file, uploadString() method
    • logStream: WriteableStream for logging hussh instance activity
    • logFile: (only when logStream absent) file to log activity

Command Execution

client.exec(command, env, callback);
client.execBuffer(command, env, callback);
client.execStatus(command, env, callback);
  • command: (String) command, including arguments
  • env: (Object) if given, the environment variables will be set (prepended to command in KEY=value style)
  • callback: (Function) called with the following:
    • err: null if OK, Error object otherwise
    • result: type depends the method used:
      • exec: ssh2 Channel (just like calling ssh2.Client.exec)
      • execBuffer: object with stdout and stderr Strings or Buffers
      • execStatus: result is omitted (undefined)

File Upload/Download

client.uploadString(stringData, remoteFile, callback);
client.upload(localFile, remoteFile, callback);
client.download(remoteFile, localFile, callback);

These are all just shortcuts which create an SFTP session, handle streams, and call the callback (receives Error on failure).

FAQs

Last updated on 09 Feb 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc