Socket
Socket
Sign inDemoInstall

node-ssh

Package Overview
Dependencies
9
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-ssh

SS2 with Promises


Version published
Weekly downloads
100K
increased by7.66%
Maintainers
1
Install size
1.10 MB
Created
Weekly downloads
 

Changelog

Source

3.0.0

  • Rename .end to .dispose
  • Rename .get to .getFile
  • Rename .put to .putFile
  • Rename .putMulti to .putFiles
  • Add .putDirectory function to copy entire directories
  • Change order of .getFile parameters
  • Extended parameter validation in .putFiles
  • Close SFTP connections after they are used
  • Hide errors from cd when cwd is supplied but it does not exist
  • Do not throw sync errors in async functions, return a rejected promise instead
  • Propagate the private key read error if it's not ENOENT (ie. permissions issue)
  • Changed the signature of input in .putFiles (ie. lowercase the props, from Local to local and from Remote to remote)

Readme

Source

Node-SSH - SSH2 with Promises

Node-SSH is an extremely lightweight Promise wrapper for ssh2, Period.

Example
var path, node_ssh, ssh

path = require('path')
node_ssh = require('node-ssh')
ssh = new node_ssh()

ssh.connect({
  host: 'localhost',
  username: 'steel',
  privateKey: '/home/steel/.ssh/id_rsa'
}).then(function() {
  // Local, Remote
  ssh.putFile('/home/steel/Lab/LocalSource', '/home/steel/Lab/RemoteTarget').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/LocalSource', remote: '/home/steel/Lab/RemoteTarget' }]).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/RemoteSource', '/home/steel/Lab/LocalTarget').then(function(Contents) {
    console.log("The File's contents were successfully downloaded")
  }, function(error) {
    console.log("Something's wrong")
    console.log(error)
  })
  // Putting entire directories
  const failed = []
  const successful = []
  ssh.putDirectory('/home/steel/Lab', '/home/steel/Lab', {
    recursive: true,
    validate: function(itemPath) {
      const baseName = path.basename(itemPath)
      return baseName.substr(0, 1) !== '.' && // do not allow dot files
             baseName !== 'node_modules' // do not allow node_modules
    },
    tick: function(localPath, remotePath, error) {
      if (error) {
        failed.push(localPath)
      } else {
        successful.push(localPath)
      }
    }
  }).then(function(successful) {
    console.log('the directory transfer was', successful ? 'successful' : 'unsuccessful')
    console.log('failed transfers', failed.join(', '))
    console.log('successful transfers', successful.join(', '))
  })
  // Command
  ssh.execCommand('hh_client --json', { cwd:'/var/www', stream: 'both' }).then(function(result) {
    console.log('STDOUT: ' + result.stdout)
    console.log('STDERR: ' + result.stderr)
  })
  // Command with escaped params
  ssh.exec('hh_client', ['--json'], { cwd: '/var/www' }).then(function(result) {
    console.log('STDOUT: ' + result)
  })
})
API
class SSH{
  connect(config: SSH2Config): Promise<this>
  requestSFTP(): Promise<SSH2SFTP>
  requestShell(): Promise<SSH2Shell>
  mkdir(path: string): Promise<string>
  exec(command: string, parameters: Array<string>, options: { cwd?: string, stdin?: string, stream?: 'stdout' | 'stderr', 'both' } = {}): Promise<Object | string>
  execCommand(command: string, options: { cwd: string, stdin: string } = {}): Promise<{ stdout: string, stderr: string, signal: ?string, code: number }>
  putFile(localFile: string, remoteFile: string, sftp: ?Object = null): Promise<void>
  getFile(localFile: string, remoteFile: string, sftp: ?Object = null): Promise<void>
  putFiles(files: Array<{ local: string, remote: string }>, sftp: ?Object = null): Promise<void>
  putDirectory(localDirectory: string, remoteDirectory: string, options: ?{ recursive: boolean, tick(localPath, remotePath, error): any, validate(localPath): boolean } = null, sftp: ?Object = null): Promise<boolean>
  dispose(): void
}

License

This project is licensed under the terms of MIT license. See the LICENSE file for more info.

Keywords

FAQs

Last updated on 22 Aug 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