Ssh

Sente includes a set of "node-ssh" based methods that allow performing operations on a remote server over the SSH protocol.

Usage

The NodeSSH library is already available, so you don't need to install it. For more detailed information and usage features, please visit https://www.npmjs.com/package/node-ssh.

const { NodeSSH } = sente;
tests/sample1.js
/* LIBRARIES
*************/
const { sente } = require('#libraries');
const { NodeSSH } = sente;

/* TEST FLOW
*************/
test = async () => {
   
  const ssh = new NodeSSH()

  ssh.connect({
    host: 'localhost',
    username: 'steel',
    privateKeyPath: '/home/steel/.ssh/id_rsa'
  })

  // or with inline privateKey

  ssh.connect({
    host: 'localhost',
    username: 'steel',
    privateKey: Buffer.from('...')
  })
  .then(function() {
    // Local, Remote
    ssh.putFile('/home/steel/Lab/localPath/fileName', '/home/steel/Lab/remotePath/fileName').then(function() {
      console.log("The File thing is done")
    }, function(error) {
      console.log("Something's wrong")
      console.log(error)
    })
    // Array<Shape('local' => string, 'remote' => string)>
    ssh.putFiles([{ local: '/home/steel/Lab/localPath/fileName', remote: '/home/steel/Lab/remotePath/fileName' }]).then(function() {
      console.log("The File thing is done")
    }, function(error) {
      console.log("Something's wrong")
      console.log(error)
    })
    // Local, Remote
    ssh.getFile('/home/steel/Lab/localPath', '/home/steel/Lab/remotePath').then(function(Contents) {
      console.log("The File's contents were successfully downloaded")
    }, function(error) {
      console.log("Something's wrong")
      console.log(error)
    }) 

Last updated