Skip to content
Nodejs tools for remote ssh connections
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
doc
src
.esdoc.json
.eslintrc.js
.gitignore
README.md
index.js
package.json

README.md

z-ssh

Nodejs tools for remote ssh connections

Install

npm i z-ssh

Usage

const conn = require('z-ssh');

Configuration file

By default ./ssh.json

conn.config = './config/ssh.json';
{
  "host": "#SERVER_IP#",
  "username": "#USERNAME#",
  "password": "#PASSWORD#",
  "local": "./mylocalfolder",
  "remote": "/var/www/vhosts/mydomain.net/httpdocs/myremotefolder"
}

If no config file is defined or a params is omitted a prompt will ask for the required param:

prompt: password:

Upload files

Upload the local folder to the remote folder:

conn.upload().then(() => {
  console.log(`Upload is done`);
  conn.close();
}).catch(err => {
  console.log(`${err}`);
  conn.close();
});

Download files

Download the remote folder to the local folder:

conn.download().then(() => {
  console.log(`Download is done`);
  conn.close();
}).catch(err => {
  console.log(`${err}`);
  conn.close();
});

Shell script on remote server

Execute a shell script on the remote server:

conn.exec('cd /var/www/vhosts/mydomain.net/httpdocs/ssh && tar -cvf backup.tar .').then(() => {
  console.log(`Action is done`);
  conn.close();
}).catch(err => {
  console.log(`${err}`);
  conn.close();
});

Shell script on local server

Execute a shell script on the local server:

conn.shell('cd /Users/myusername/Documents/myfolder && tar -cvf backup.tar .').then(() => {
  console.log(`Action is done`);
  conn.close();
}).catch(err => {
  console.log(`${err}`);
  conn.close();
});

Contributing and issues

Contributors are welcome, please fork and send pull requests! If you have any ideas on how to make this project better then please submit an issue or send me an email.

License

©2017 Zguillez.io

Original code licensed under MIT Open Source projects used within this project retain their original licenses.

Changelog

v0.1.0 (January 27, 2017)

  • Upload and download methods
You can’t perform that action at this time.