{"name":"node-ssh","version":"13.1.0","keywords":["ssh","ssh2","sftp"],"author":{"name":"steelbrain"},"license":"MIT","_id":"node-ssh@13.1.0","maintainers":[{"name":"steelbrain","email":"hello@aneesiqbal.ai"}],"homepage":"https://github.com/steelbrain/node-ssh#readme","bugs":{"url":"https://github.com/steelbrain/node-ssh/issues"},"ava":{"files":["test/*-test.ts"],"require":["ts-node/register/transpile-only"],"extensions":["ts"]},"dist":{"shasum":"fca947200d61db9a5f9915e27c252e133b79e6bf","tarball":"http://registry-npm.ywwl.com/node-ssh/download/node-ssh-13.1.0.tgz","fileCount":6,"integrity":"sha512-GLcw49yFd9+rUpP+FgX6wrF/N90cmuDl2n0i8d3L828b6riRjkb9w3SS+XvviRWbrAhLxuMKywFqxvQDZQ1bug==","signatures":[{"sig":"MEUCIQC5jn7oJSOksXLcwNuEAuHeqBnofCy/kNDlxA1xSgprlAIgLHpCM7tKjOyDyCTfOuWoCmqHYYw26gVTKFtcgx6f+sE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":77083,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLwK2ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmprpg/+NehRIw0vViYkdajQGiZMUIfnTuPlWKqyUlpbxCEJKOrJOwzs\r\nzJbXqGdc1iGz/Q4uhNtsS5uq+p0aI/+axqzfY2ezMV/kby6a0O36GRXF1atD\r\nZMwG17p8zRSWPv127Qvde1+R8XXuiqGGA/Ld/1obCOSoyOObPRnHBST3/xnG\r\nqYOTCcEOtc/bCBIDOXL4XSAyGaPPmDNqMsEzYDe0kFW/yl4+26koQRMLgAEk\r\nht/STMw0ah64+af+Ft1LRV4IGTdrRkz8dPBPNJfGPk/UdQOsGeT0VKq592zs\r\ndU91rq4RUjlYf6HoTlnn3lpvkOTvf+WNgYiVm/J3z46AryBagstNfBcBKvpc\r\nDiHTVEebsj/g0s8XhNXUU67TJyMSNr7Pv8PDggqasvyLcXmTI6uEhwuwqFVN\r\nyPNTiCsm+u/WTnE2wWHKBFN6VZWI2Z79T0xKtfvy1xJBRgiTpyWOe9xJJyoB\r\nHZFiS+7iXi9qNyrIM2slRFxC+mGQWjc83507smh0Bj+1Mdq7XKqF5AQn+n56\r\ntWUSBClh/xzIoTsacLr7EaSs1pR7MdR8tY+V4j3C/P9OhVgzqEO+kYbDR8Tx\r\nKX1gp0wkQGvBk4HC1lg4etRr3TyhXJg7lChUZaGS6Wyb4sWZL1ZbKDh6DeX+\r\neVGzb1eNWzcrKABAkab+LwlyUTlguHk1Jrk=\r\n=SxFG\r\n-----END PGP SIGNATURE-----\r\n","size":13989,"noattachment":false,"key":"/node-ssh/-/node-ssh-13.1.0.tgz"},"main":"lib/cjs/index.js","type":"commonjs","module":"lib/esm/index.mjs","engines":{"node":">= 10"},"exports":{".":{"types":"./lib/typings/index.d.ts","import":"./lib/esm/index.mjs","require":"./lib/cjs/index.js"},"./package.json":"./package.json"},"gitHead":"53c44296d1455eaa7a741e46eae775846b07dba8","scripts":{"lint":"(tsc -p . --noEmit) && (eslint . --ext .ts) && (prettier --list-different src/*.ts)","test":"ava","prepare":"yarn build:clean ; yarn build:cjs ; yarn build:esm ; yarn build:typings","build:cjs":"tsc --module commonjs --target es2018 --outDir lib/cjs","build:esm":"tsc --module es2015 --target es2018 --outDir lib/esm && mv lib/esm/index.js lib/esm/index.mjs","build:clean":"rm -rf lib","build:typings":"tsc --declaration --outDir lib/typings --emitDeclarationOnly"},"typings":"lib/typings/index.d.ts","_npmUser":{"name":"steelbrain","email":"hello@aneesiqbal.ai"},"repository":{"url":"git+https://github.com/steelbrain/node-ssh.git","type":"git"},"_npmVersion":"8.19.3","description":"SSH2 with Promises","directories":{},"_nodeVersion":"16.19.0","dependencies":{"ssh2":"^1.11.0","make-dir":"^3.1.0","is-stream":"^2.0.0","sb-scandir":"^3.1.0","@types/ssh2":"^1.11.9","shell-escape":"^0.2.0","sb-promise-queue":"^2.1.0"},"_hasShrinkwrap":false,"devDependencies":{"ava":"^3.15.0","ts-node":"^10.1.0","node-pty":"^0.10.1","typescript":"^4.3.5","ssh2-streams":"^0.4.10","@types/shell-escape":"^0.2.0","eslint-config-steelbrain":"^11.0.0"},"_npmOperationalInternal":{"tmp":"tmp/node-ssh_13.1.0_1680802486386_0.8359783353943109","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":1680802486563,"_cnpm_publish_time":1680802486563,"dist-tags":{"beta":"12.0.4-beta1","latest":"13.2.1"}}