1 |
|
2 |
|
3 | import SSH2, { AcceptConnection, Channel, ClientChannel, ConnectConfig, ExecOptions, Prompt, PseudoTtyOptions, RejectConnection, SFTPWrapper, ShellOptions, TcpConnectionDetails, TransferOptions, UNIXConnectionDetails } from 'ssh2';
|
4 | import stream from 'stream';
|
5 | export type Config = ConnectConfig & {
|
6 | password?: string;
|
7 | privateKey?: string;
|
8 | privateKeyPath?: string;
|
9 | tryKeyboard?: boolean;
|
10 | onKeyboardInteractive?: (name: string, instructions: string, lang: string, prompts: Prompt[], finish: (responses: string[]) => void) => void;
|
11 | };
|
12 | export interface SSHExecCommandOptions {
|
13 | cwd?: string;
|
14 | stdin?: string | stream.Readable;
|
15 | execOptions?: ExecOptions;
|
16 | encoding?: BufferEncoding;
|
17 | noTrim?: boolean;
|
18 | onChannel?: (clientChannel: ClientChannel) => void;
|
19 | onStdout?: (chunk: Buffer) => void;
|
20 | onStderr?: (chunk: Buffer) => void;
|
21 | }
|
22 | export interface SSHExecCommandResponse {
|
23 | stdout: string;
|
24 | stderr: string;
|
25 | code: number | null;
|
26 | signal: string | null;
|
27 | }
|
28 | export interface SSHExecOptions extends SSHExecCommandOptions {
|
29 | stream?: 'stdout' | 'stderr' | 'both';
|
30 | }
|
31 | export interface SSHPutFilesOptions {
|
32 | sftp?: SFTPWrapper | null;
|
33 | concurrency?: number;
|
34 | transferOptions?: TransferOptions;
|
35 | }
|
36 | export interface SSHGetPutDirectoryOptions extends SSHPutFilesOptions {
|
37 | tick?: (localFile: string, remoteFile: string, error: Error | null) => void;
|
38 | validate?: (path: string) => boolean;
|
39 | recursive?: boolean;
|
40 | }
|
41 | export type SSHMkdirMethod = 'sftp' | 'exec';
|
42 | export type SSHForwardInListener = (details: TcpConnectionDetails, accept: AcceptConnection<ClientChannel>, reject: RejectConnection) => void;
|
43 | export interface SSHForwardInDetails {
|
44 | dispose(): Promise<void>;
|
45 | port: number;
|
46 | }
|
47 | export type SSHForwardInStreamLocalListener = (info: UNIXConnectionDetails, accept: AcceptConnection, reject: RejectConnection) => void;
|
48 | export interface SSHForwardInStreamLocalDetails {
|
49 | dispose(): Promise<void>;
|
50 | }
|
51 | export declare class SSHError extends Error {
|
52 | code: string | null;
|
53 | constructor(message: string, code?: string | null);
|
54 | }
|
55 | export declare class NodeSSH {
|
56 | connection: SSH2.Client | null;
|
57 | private getConnection;
|
58 | connect(givenConfig: Config): Promise<this>;
|
59 | isConnected(): boolean;
|
60 | requestShell(options?: PseudoTtyOptions | ShellOptions | false): Promise<ClientChannel>;
|
61 | withShell(callback: (channel: ClientChannel) => Promise<void>, options?: PseudoTtyOptions | ShellOptions | false): Promise<void>;
|
62 | requestSFTP(): Promise<SFTPWrapper>;
|
63 | withSFTP(callback: (sftp: SFTPWrapper) => Promise<void>): Promise<void>;
|
64 | execCommand(givenCommand: string, options?: SSHExecCommandOptions): Promise<SSHExecCommandResponse>;
|
65 | exec(command: string, parameters: string[], options?: SSHExecOptions & {
|
66 | stream?: 'stdout' | 'stderr';
|
67 | }): Promise<string>;
|
68 | exec(command: string, parameters: string[], options?: SSHExecOptions & {
|
69 | stream: 'both';
|
70 | }): Promise<SSHExecCommandResponse>;
|
71 | mkdir(path: string, method?: SSHMkdirMethod, givenSftp?: SFTPWrapper | null): Promise<void>;
|
72 | getFile(localFile: string, remoteFile: string, givenSftp?: SFTPWrapper | null, transferOptions?: TransferOptions | null): Promise<void>;
|
73 | putFile(localFile: string, remoteFile: string, givenSftp?: SFTPWrapper | null, transferOptions?: TransferOptions | null): Promise<void>;
|
74 | putFiles(files: {
|
75 | local: string;
|
76 | remote: string;
|
77 | }[], { concurrency, sftp: givenSftp, transferOptions }?: SSHPutFilesOptions): Promise<void>;
|
78 | putDirectory(localDirectory: string, remoteDirectory: string, { concurrency, sftp: givenSftp, transferOptions, recursive, tick, validate, }?: SSHGetPutDirectoryOptions): Promise<boolean>;
|
79 | getDirectory(localDirectory: string, remoteDirectory: string, { concurrency, sftp: givenSftp, transferOptions, recursive, tick, validate, }?: SSHGetPutDirectoryOptions): Promise<boolean>;
|
80 | forwardIn(remoteAddr: string, remotePort: number, onConnection?: SSHForwardInListener): Promise<SSHForwardInDetails>;
|
81 | forwardOut(srcIP: string, srcPort: number, dstIP: string, dstPort: number): Promise<Channel>;
|
82 | forwardInStreamLocal(socketPath: string, onConnection?: SSHForwardInStreamLocalListener): Promise<SSHForwardInStreamLocalDetails>;
|
83 | forwardOutStreamLocal(socketPath: string): Promise<Channel>;
|
84 | dispose(): void;
|
85 | }
|