https://github.com/rumkin/ssh-shell
SSH remote shell client implementation
https://github.com/rumkin/ssh-shell
Last synced: about 1 year ago
JSON representation
SSH remote shell client implementation
- Host: GitHub
- URL: https://github.com/rumkin/ssh-shell
- Owner: rumkin
- Created: 2016-06-10T12:39:17.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-07T11:38:25.000Z (almost 10 years ago)
- Last Synced: 2024-04-23T11:03:19.318Z (about 2 years ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# SSH Shell
SSH shell is a util to manage shell commands variables and manage files upload/download.
It has the same interface as local-shell to simplify usage.
## Installation
Install via npm
```
npm i ssh-shell
```
## Example
Example of variable usage:
```javascript
const SshShell = require('ssh-shell');
const shell = new SshShell({
username: 'user',
password: '********',
cwd: '/home/user',
});
shell.open()
.then(() => {
shell.set('NAME', 'World');
shell.exec('echo Hello $NAME')
.then(({code, io}) => {
if (code) {
throw new Error('Exit code is ' + code);
}
console.log(io.toString()); // -> Hello World
return shell.close();
});
});
```
## API
### exec(cmd:String) -> Promise<{code,io},Error>
Execute command and return promised Result object.
### open()
_Added for compatibility with SshShell_
Start session. Emit `open` event.
### close()
_Added for compatibility with SshShell_
Stop session. Emit `close` event.
### uploadFile(source:String, [dest:String]) -> Promise()
Upload file from source to destination. Destination is resolving from `cwd` value. If destination not set than it replaces with source's filename.
### uploadBuffer(source:Buffer, dest:string) -> Promise()
Upload data from buffer to the server.
### downloadFile(source:String, [dest:String])
Download file from source into destination. If destination not set than it replaces with source's filename.