node-ssh-tunnel
Version:
Node-SSH-Tunnel
50 lines (49 loc) • 1.68 kB
TypeScript
import { Server } from 'net';
import { Client, ConnectConfig } from 'ssh2';
export type SshOptions = ConnectConfig;
/**
* Controls be behaviour of the tunnel server.
*/
export interface TunnelOptions {
autoClose?: boolean;
/**
* If set to true, when ssh connection is broken, the tunnel will be re-created.
* @default false
*/
reconnectOnError?: boolean;
}
/**
* If the `srcAddr` or `srcPort` is not defined, the adress will be taken from the local TCP server
*/
export interface ForwardOptions {
srcAddr?: string;
srcPort: number;
dstAddr?: string;
dstPort: number;
}
export declare class SSHError extends Error {
private code;
constructor(message: string, code?: string);
}
export declare class NodeSSHTunnel {
private connection;
private sshOptions;
private servers;
private reconnecting;
constructor();
getConnection(): Client;
isConnected(): boolean;
connect(sshOptions: SshOptions): Promise<this>;
reConnect(): Promise<Client>;
disconnect(): Promise<void>;
close(): Promise<void>;
closeTunnel(): Promise<void>;
createTunnel(forwardOptions: ForwardOptions | ForwardOptions[], tunnelOptions?: TunnelOptions): Promise<void>;
}
export declare const createTunnel: (sshOptions: SshOptions, forwardOptions: ForwardOptions[] | ForwardOptions, tunnelOptions?: TunnelOptions) => Promise<{
servers: (Server | undefined)[];
sshConnection: Client;
close: () => void;
}>;
export declare const createTunnelEx: (sshOptions: SshOptions, forwardOptions: ForwardOptions[] | ForwardOptions, tunnelOptions?: TunnelOptions) => Promise<NodeSSHTunnel>;
export default createTunnel;