{"name":"node-ssh","version":"6.0.0","keywords":["ssh","ssh2","sftp"],"author":{"name":"steelbrain","email":"i@steelbrain.me"},"license":"MIT","_id":"node-ssh@6.0.0","maintainers":[{"name":"steelbrain","email":"i@steelbrain.me"}],"homepage":"https://github.com/steelbrain/node-ssh#readme","bugs":{"url":"https://github.com/steelbrain/node-ssh/issues"},"ava":{"files":["spec/*.js"],"require":["@babel/register"]},"dist":{"shasum":"3287bdb3fad4a898064ea1df2d601a65a1c5d724","tarball":"http://registry-npm.ywwl.com/node-ssh/download/node-ssh-6.0.0.tgz","fileCount":13,"integrity":"sha512-R/nqH09/kZrXilSLizJgokw4hJTSADANnntjk6iNVfO95RPNQq9H19NeUvQof96WQB9dgOxpRgBV7d+snZP2DQ==","signatures":[{"sig":"MEUCIQCgeZwDU4MSKqTKhqybrypDOccoKfGyf2XZDvzJUnu7jwIgX+9xz4reovkAki47T/OdXW14qU5IHikne1SBBh4C9zM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":33635,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJctKaBCRA9TVsSAnZWagAAm6wP/0u2t8OtIs2QUaG4cs9C\n/C5KKbFxjjSfgh9PT37wTtFdKzx8dG6eTrlenwuJy4gfcDvL6HewEn625Y9T\nx86CvIc0DWBm8kYyeGL3xh1YbSM/Wo+cKjGujVnik0gQ9kJQJ4YFt2bw6uPb\ngIYrA3ikZHmsVqeQhcITNYvb/oHzRSa+2tpl83OO3wkiq6RiXYnQVcmxyg/6\n+fIWBDzux0yqw7M8SRLEY5mV7mLVUuoL0SFUP5pYQ3EU+ktZCZdD7A90YK2L\nSP4Nz4RVtF5vwZ5sPXDNX4uQ9Jc8oqPSLdVU8YanKiuiNDzbC0ziZ7AjoTju\nVNN+8/DRz7MJXJVsezbrWlL9cpO6SVSKWzAj0FOSZ+CNRoKB56ElILVHEWJJ\nHG4YIdeFeKmsc8/f9eFHTFHt0beUVoA29KpYI2HZ0KV0AFfIaWwZOFNPvJhv\nQaaucV2Nf/1zeiIFxKT8bNaDJsXWSfY5D5C1iAbYkNW1mNPx1CK4IFXC6Z3l\nImwTwSLklJi+6JuRaOgBo/kA+XfTYg+e9R5Vp+AyHJW3yyCK99/OifsPu8aC\nCL7jLI7B4CuKmHpcImFZsV9cuqk80l5LmHRvVGOMMt2EdR3atWa35WrwT5xo\nMGp+aaVnSiptpgjQKkTqrhRBGrMSKHThed+yD3aAEvSb07H4qIAGrQZnBYIP\nse90\r\n=LJ2o\r\n-----END PGP SIGNATURE-----\r\n","size":9303,"noattachment":false,"key":"/node-ssh/-/node-ssh-6.0.0.tgz"},"main":"lib/index.js","gitHead":"1a4cb4a9cb240eddd3843fc7d4feaa91db797f53","scripts":{"test":"(npm run test:spec) && (npm run test:flow) && (npm run test:lint) && (npm run test:prettier)","watch":"npm run prepare -- -w","prepare":"sb-babel-cli -o lib src","test:flow":"flow check","test:lint":"eslint .","test:spec":"ava spec/*-spec.js","test:prettier":"prettier -l '{src,spec}/**/*.js'"},"_npmUser":{"name":"steelbrain","email":"i@steelbrain.me"},"repository":{"url":"git+https://github.com/steelbrain/node-ssh.git","type":"git"},"_npmVersion":"6.4.1","description":"SS2 with Promises","directories":{},"_nodeVersion":"10.15.3","dependencies":{"ssh2":"^0.8.2","p-map":"^2.1.0","sb-scandir":"^2.0.0","sb-promisify":"^2.0.1","shell-escape":"^0.2.0"},"_hasShrinkwrap":false,"devDependencies":{"ava":"^1.4.1","pty.js":"^0.3.1","flow-bin":"^0.97.0","prettier":"^1.17.0","@babel/core":"^7.4.3","sb-babel-cli":"^1.2.1","ssh2-streams":"^0.4.2","@babel/register":"^7.4.0","@babel/preset-env":"^7.4.3","@babel/preset-flow":"^7.0.0","eslint-config-steelbrain":"^7.0.0"},"_npmOperationalInternal":{"tmp":"tmp/node-ssh_6.0.0_1555342976761_0.7074418998927974","host":"s3://npm-registry-packages"},"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":1555342976951,"_cnpm_publish_time":1555342976951,"dist-tags":{"beta":"12.0.4-beta1","latest":"13.2.1"}}