/// /// import SSH2, { AcceptConnection, Channel, ClientChannel, ConnectConfig, ExecOptions, Prompt, PseudoTtyOptions, RejectConnection, SFTPWrapper, ShellOptions, TcpConnectionDetails, TransferOptions, UNIXConnectionDetails } from 'ssh2'; import stream from 'stream'; export type Config = ConnectConfig & { password?: string; privateKey?: string; privateKeyPath?: string; tryKeyboard?: boolean; onKeyboardInteractive?: (name: string, instructions: string, lang: string, prompts: Prompt[], finish: (responses: string[]) => void) => void; }; export interface SSHExecCommandOptions { cwd?: string; stdin?: string | stream.Readable; execOptions?: ExecOptions; encoding?: BufferEncoding; noTrim?: boolean; onChannel?: (clientChannel: ClientChannel) => void; onStdout?: (chunk: Buffer) => void; onStderr?: (chunk: Buffer) => void; } export interface SSHExecCommandResponse { stdout: string; stderr: string; code: number | null; signal: string | null; } export interface SSHExecOptions extends SSHExecCommandOptions { stream?: 'stdout' | 'stderr' | 'both'; } export interface SSHPutFilesOptions { sftp?: SFTPWrapper | null; concurrency?: number; transferOptions?: TransferOptions; } export interface SSHGetPutDirectoryOptions extends SSHPutFilesOptions { tick?: (localFile: string, remoteFile: string, error: Error | null) => void; validate?: (path: string) => boolean; recursive?: boolean; } export type SSHMkdirMethod = 'sftp' | 'exec'; export type SSHForwardInListener = (details: TcpConnectionDetails, accept: AcceptConnection, reject: RejectConnection) => void; export interface SSHForwardInDetails { dispose(): Promise; port: number; } export type SSHForwardInStreamLocalListener = (info: UNIXConnectionDetails, accept: AcceptConnection, reject: RejectConnection) => void; export interface SSHForwardInStreamLocalDetails { dispose(): Promise; } export declare class SSHError extends Error { code: string | null; constructor(message: string, code?: string | null); } export declare class NodeSSH { connection: SSH2.Client | null; private getConnection; connect(givenConfig: Config): Promise; isConnected(): boolean; requestShell(options?: PseudoTtyOptions | ShellOptions | false): Promise; withShell(callback: (channel: ClientChannel) => Promise, options?: PseudoTtyOptions | ShellOptions | false): Promise; requestSFTP(): Promise; withSFTP(callback: (sftp: SFTPWrapper) => Promise): Promise; execCommand(givenCommand: string, options?: SSHExecCommandOptions): Promise; exec(command: string, parameters: string[], options?: SSHExecOptions & { stream?: 'stdout' | 'stderr'; }): Promise; exec(command: string, parameters: string[], options?: SSHExecOptions & { stream: 'both'; }): Promise; mkdir(path: string, method?: SSHMkdirMethod, givenSftp?: SFTPWrapper | null): Promise; getFile(localFile: string, remoteFile: string, givenSftp?: SFTPWrapper | null, transferOptions?: TransferOptions | null): Promise; putFile(localFile: string, remoteFile: string, givenSftp?: SFTPWrapper | null, transferOptions?: TransferOptions | null): Promise; putFiles(files: { local: string; remote: string; }[], { concurrency, sftp: givenSftp, transferOptions }?: SSHPutFilesOptions): Promise; putDirectory(localDirectory: string, remoteDirectory: string, { concurrency, sftp: givenSftp, transferOptions, recursive, tick, validate, }?: SSHGetPutDirectoryOptions): Promise; getDirectory(localDirectory: string, remoteDirectory: string, { concurrency, sftp: givenSftp, transferOptions, recursive, tick, validate, }?: SSHGetPutDirectoryOptions): Promise; forwardIn(remoteAddr: string, remotePort: number, onConnection?: SSHForwardInListener): Promise; forwardOut(srcIP: string, srcPort: number, dstIP: string, dstPort: number): Promise; forwardInStreamLocal(socketPath: string, onConnection?: SSHForwardInStreamLocalListener): Promise; forwardOutStreamLocal(socketPath: string): Promise; dispose(): void; }