{"name":"node-ssh","version":"4.0.1","keywords":["ssh","ssh2","sftp"],"author":{"name":"steelbrain","email":"i@steelbrain.me"},"license":"MIT","_id":"node-ssh@4.0.1","maintainers":[{"name":"steelbrain","email":"aneesiqbalbhatti@gmail.com"}],"homepage":"https://github.com/steelbrain/node-ssh#readme","bugs":{"url":"https://github.com/steelbrain/node-ssh/issues"},"dist":{"shasum":"fe632bbfc793dc18c6cc3fcf9e36d5f9ad6a3369","tarball":"http://registry-npm.ywwl.com/node-ssh/download/node-ssh-4.0.1.tgz","integrity":"sha512-u+lI4N8Zqu3HodcLFJWfP1svkgdtOCWDk//OU0lFmiOUvQ3t6PD4c5e8g/HN8SQMtG4xAK1dZacpfixYn8QL4w==","signatures":[{"sig":"MEYCIQC/A9lQRYKrrF/z3SG+nPoEZAGlTzJgZp9vJ/AU+Q23JAIhAItu0V7fR7tBs+/gO2s5cCUG2izyQVnstZnkp47mcbBS","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"size":8153,"noattachment":false,"key":"/node-ssh/-/node-ssh-4.0.1.tgz"},"main":"lib/index.js","_from":".","_shasum":"fe632bbfc793dc18c6cc3fcf9e36d5f9ad6a3369","gitHead":"591497edbf3fe2ae32b518e5d0d868c6318dabac","scripts":{"test":"(apm test) && (flow check) && (eslint . )","build":"npm run clean; babel src --out-dir lib","clean":"rm -rf lib","watch":"npm run clean; babel src --out-dir lib --watch"},"_npmUser":{"name":"steelbrain","email":"i@steelbrain.me"},"repository":{"url":"git+https://github.com/steelbrain/node-ssh.git","type":"git"},"_npmVersion":"4.0.5","description":"SS2 with Promises","directories":{},"_nodeVersion":"7.4.0","dependencies":{"ssh2":"^0.5.0","mkdirp":"^0.5.1","sb-scandir":"^1.0.0","sb-promisify":"^2.0.1","shell-escape":"^0.2.0"},"devDependencies":{"pty.js":"^0.3.1","flow-bin":"^0.32.0","babel-cli":"^6.11.4","jasmine-fix":"^1.0.1","ssh2-streams":"^0.1.6","babel-preset-steelbrain":"^4.0.2","eslint-config-steelbrain":"^1.0.4"},"_npmOperationalInternal":{"tmp":"tmp/node-ssh-4.0.1.tgz_1485389613825_0.6627733141649514","host":"packages-18-east.internal.npmjs.com"},"readme":"Node-SSH - SSH2 with Promises\n=========\n\nNode-SSH is an extremely lightweight Promise wrapper for [ssh2][ssh2].\n\n#### Installation\n\n```sh\n$ npm install node-ssh # If you're using npm\n$ yarn add node-ssh # If you're using Yarn\n```\n\n#### Example\n\n```js\nconst fs = require('fs')\nconst path = require('path')\nconst {NodeSSH} = require('node-ssh')\n\nconst ssh = new NodeSSH()\n\nssh.connect({\n  host: 'localhost',\n  username: 'steel',\n  privateKeyPath: '/home/steel/.ssh/id_rsa'\n})\n\n// or with inline privateKey\n\nssh.connect({\n  host: 'localhost',\n  username: 'steel',\n  privateKey: Buffer.from('...')\n})\n.then(function() {\n  // Local, Remote\n  ssh.putFile('/home/steel/Lab/localPath/fileName', '/home/steel/Lab/remotePath/fileName').then(function() {\n    console.log(\"The File thing is done\")\n  }, function(error) {\n    console.log(\"Something's wrong\")\n    console.log(error)\n  })\n  // Array<Shape('local' => string, 'remote' => string)>\n  ssh.putFiles([{ local: '/home/steel/Lab/localPath/fileName', remote: '/home/steel/Lab/remotePath/fileName' }]).then(function() {\n    console.log(\"The File thing is done\")\n  }, function(error) {\n    console.log(\"Something's wrong\")\n    console.log(error)\n  })\n  // Local, Remote\n  ssh.getFile('/home/steel/Lab/localPath', '/home/steel/Lab/remotePath').then(function(Contents) {\n    console.log(\"The File's contents were successfully downloaded\")\n  }, function(error) {\n    console.log(\"Something's wrong\")\n    console.log(error)\n  })\n  // Putting entire directories\n  const failed = []\n  const successful = []\n  ssh.putDirectory('/home/steel/Lab', '/home/steel/Lab', {\n    recursive: true,\n    concurrency: 10,\n    // ^ WARNING: Not all servers support high concurrency\n    // try a bunch of values and see what works on your server\n    validate: function(itemPath) {\n      const baseName = path.basename(itemPath)\n      return baseName.substr(0, 1) !== '.' && // do not allow dot files\n             baseName !== 'node_modules' // do not allow node_modules\n    },\n    tick: function(localPath, remotePath, error) {\n      if (error) {\n        failed.push(localPath)\n      } else {\n        successful.push(localPath)\n      }\n    }\n  }).then(function(status) {\n    console.log('the directory transfer was', status ? 'successful' : 'unsuccessful')\n    console.log('failed transfers', failed.join(', '))\n    console.log('successful transfers', successful.join(', '))\n  })\n  // Command\n  ssh.execCommand('hh_client --json', { cwd:'/var/www' }).then(function(result) {\n    console.log('STDOUT: ' + result.stdout)\n    console.log('STDERR: ' + result.stderr)\n  })\n  // Command with escaped params\n  ssh.exec('hh_client', ['--json'], { cwd: '/var/www', stream: 'stdout', options: { pty: true } }).then(function(result) {\n    console.log('STDOUT: ' + result)\n  })\n  // With streaming stdout/stderr callbacks\n  ssh.exec('hh_client', ['--json'], {\n    cwd: '/var/www',\n    onStdout(chunk) {\n      console.log('stdoutChunk', chunk.toString('utf8'))\n    },\n    onStderr(chunk) {\n      console.log('stderrChunk', chunk.toString('utf8'))\n    },\n  })\n})\n```\n\n#### API\n\n```ts\n// API reference in Typescript typing format:\nimport SSH2, {\n  AcceptConnection,\n  Channel,\n  ClientChannel,\n  ConnectConfig,\n  ExecOptions,\n  Prompt,\n  PseudoTtyOptions,\n  RejectConnection,\n  SFTPWrapper,\n  ShellOptions,\n  TcpConnectionDetails,\n  TransferOptions,\n  UNIXConnectionDetails,\n} from 'ssh2'\nimport stream from 'stream'\n\n// ^ You do NOT need to import these package, these are here for reference of where the\n// types are coming from.\n\nexport type Config = ConnectConfig & {\n  password?: string\n  privateKey?: string\n  privateKeyPath?: string\n  tryKeyboard?: boolean\n  onKeyboardInteractive?: (\n    name: string,\n    instructions: string,\n    lang: string,\n    prompts: Prompt[],\n    finish: (responses: string[]) => void,\n  ) => void\n}\nexport interface SSHExecCommandOptions {\n  cwd?: string\n  stdin?: string | stream.Readable\n  execOptions?: ExecOptions\n  encoding?: BufferEncoding\n  noTrim?: boolean\n  onChannel?: (clientChannel: ClientChannel) => void\n  onStdout?: (chunk: Buffer) => void\n  onStderr?: (chunk: Buffer) => void\n}\nexport interface SSHExecCommandResponse {\n  stdout: string\n  stderr: string\n  code: number | null\n  signal: string | null\n}\nexport interface SSHExecOptions extends SSHExecCommandOptions {\n  stream?: 'stdout' | 'stderr' | 'both'\n}\nexport interface SSHPutFilesOptions {\n  sftp?: SFTPWrapper | null\n  concurrency?: number\n  transferOptions?: TransferOptions\n}\nexport interface SSHGetPutDirectoryOptions extends SSHPutFilesOptions {\n  tick?: (localFile: string, remoteFile: string, error: Error | null) => void\n  validate?: (path: string) => boolean\n  recursive?: boolean\n}\nexport type SSHMkdirMethod = 'sftp' | 'exec'\nexport type SSHForwardInListener = (\n  details: TcpConnectionDetails,\n  accept: AcceptConnection<ClientChannel>,\n  reject: RejectConnection,\n) => void\nexport interface SSHForwardInDetails {\n  dispose(): Promise<void>\n  port: number\n}\nexport type SSHForwardInStreamLocalListener = (\n  info: UNIXConnectionDetails,\n  accept: AcceptConnection,\n  reject: RejectConnection,\n) => void\nexport interface SSHForwardInStreamLocalDetails {\n  dispose(): Promise<void>\n}\nexport class SSHError extends Error {\n  code: string | null\n  constructor(message: string, code?: string | null)\n}\n\nexport class NodeSSH {\n  connection: SSH2.Client | null\n\n  connect(config: Config): Promise<this>\n  isConnected(): boolean\n  requestShell(options?: PseudoTtyOptions | ShellOptions | false): Promise<ClientChannel>\n  withShell(\n    callback: (channel: ClientChannel) => Promise<void>,\n    options?: PseudoTtyOptions | ShellOptions | false,\n  ): Promise<void>\n  requestSFTP(): Promise<SFTPWrapper>\n  withSFTP(callback: (sftp: SFTPWrapper) => Promise<void>): Promise<void>\n  execCommand(givenCommand: string, options?: SSHExecCommandOptions): Promise<SSHExecCommandResponse>\n  exec(\n    command: string,\n    parameters: string[],\n    options?: SSHExecOptions & {\n      stream?: 'stdout' | 'stderr'\n    },\n  ): Promise<string>\n  exec(\n    command: string,\n    parameters: string[],\n    options?: SSHExecOptions & {\n      stream: 'both'\n    },\n  ): Promise<SSHExecCommandResponse>\n  mkdir(path: string, method?: SSHMkdirMethod, givenSftp?: SFTPWrapper | null): Promise<void>\n  getFile(\n    localFile: string,\n    remoteFile: string,\n    givenSftp?: SFTPWrapper | null,\n    transferOptions?: TransferOptions | null,\n  ): Promise<void>\n  putFile(\n    localFile: string,\n    remoteFile: string,\n    givenSftp?: SFTPWrapper | null,\n    transferOptions?: TransferOptions | null,\n  ): Promise<void>\n  putFiles(\n    files: {\n      local: string\n      remote: string\n    }[],\n    { concurrency, sftp: givenSftp, transferOptions }?: SSHPutFilesOptions,\n  ): Promise<void>\n  putDirectory(\n    localDirectory: string,\n    remoteDirectory: string,\n    { concurrency, sftp: givenSftp, transferOptions, recursive, tick, validate }?: SSHGetPutDirectoryOptions,\n  ): Promise<boolean>\n  getDirectory(\n    localDirectory: string,\n    remoteDirectory: string,\n    { concurrency, sftp: givenSftp, transferOptions, recursive, tick, validate }?: SSHGetPutDirectoryOptions,\n  ): Promise<boolean>\n  forwardIn(remoteAddr: string, remotePort: number, onConnection?: SSHForwardInListener): Promise<SSHForwardInDetails>\n  forwardOut(srcIP: string, srcPort: number, dstIP: string, dstPort: number): Promise<Channel>\n  forwardInStreamLocal(\n    socketPath: string,\n    onConnection?: SSHForwardInStreamLocalListener,\n  ): Promise<SSHForwardInStreamLocalDetails>\n  forwardOutStreamLocal(socketPath: string): Promise<Channel>\n  dispose(): void\n}\n```\n\n### Typescript support\n\n`node-ssh` requires extra dependencies while working under Typescript. Please install them as shown below\n\n```\nyarn add --dev @types/ssh2\n# OR\nnpm install --save-dev @types/ssh2\n```\n\nIf you're still running into issues, try adding these to your `tsconfig.json`\n\n```json\n{\n  \"compilerOptions\": {\n    \"moduleResolution\": \"node\",\n    \"allowSyntheticDefaultImports\": true\n  }\n}\n```\n\n### Keyboard-interactive user authentication\n\nIn some cases you have to enable keyboard-interactive user authentication.\nOtherwise you will get an `All configured authentication methods failed` error.\n\n#### Example:\n\n```js\nconst password = 'test'\n\nssh.connect({\n  host: 'localhost',\n  username: 'steel',\n  port: 22,\n  password,\n  tryKeyboard: true,\n})\n\n// Or if you want to add some custom keyboard-interactive logic:\n\nssh.connect({\n  host: 'localhost',\n  username: 'steel',\n  port: 22,\n  tryKeyboard: true,\n  onKeyboardInteractive(name, instructions, instructionsLang, prompts, finish) {\n    if (prompts.length > 0 && prompts[0].prompt.toLowerCase().includes('password')) {\n      finish([password])\n    }\n  }\n})\n```\n\nFor further information see: https://github.com/mscdex/ssh2/issues/604\n\n### License\nThis project is licensed under the terms of MIT license. See the LICENSE file for more info.\n\n[ssh2]:https://github.com/mscdex/ssh2\n","publish_time":1485389614416,"_cnpm_publish_time":1485389614416,"dist-tags":{"beta":"12.0.4-beta1","latest":"13.2.1"}}