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 = var client = ; // upload a string to a remote fileclient; // execute a command and save all buffered outputclient;
Instantiation
var client = ;
- 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.
- username: if not set, will be set according to precedence:
- 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;client;client;
- 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;client;client;
These are all just shortcuts which create an SFTP session, handle streams, and call the callback (receives Error on failure).