UNPKG

hivessh

Version:

HiveSsh is an innovative library designed to streamline SSH2 connections and simplify task execution on Linux servers.

111 lines 5.28 kB
import net from "net"; import { ClientChannel, Client as SshClient } from "ssh2"; import { ExecSession } from "./ExecSession.js"; import { CmdChannelOptions, CmdExecOptions, SshChannel, SshChannelExit } from "./SshExec.js"; import { SshHostOptions, SshHostSettings } from "./SshHostOptions.js"; import { SshTunnelOutOptions } from "./SshTunnel.js"; import { AbstractPackageManager } from "./apm/apm.js"; import { OsRelease } from "./essentials/OsRelease.js"; import { SFTPPromiseWrapper } from "./essentials/SftpPromiseWrapper.js"; import { Awaitable } from "./utils/base.js"; export declare class SshHost { settings: SshHostSettings; closeErr?: Error | string; connected: boolean; ssh: SshClient; sftp: SFTPPromiseWrapper; release: OsRelease; /** * * @description The only public function to create a SshHost object. * @param options Connection options for the ssh host * @returns A promise that resolves when the connection is established and the promise provides you an SshHost object */ static connect(options: SshHostOptions): Promise<SshHost>; private constructor(); private connect; private emergencyClose; /** * @description If the SshHost socket is closed because of an error this method throws that error. * @throws Ssh socket close reason */ throwCloseError(): void | never; /** * @deprecated Use disconnect() * @description Closes the ssh socket if still connected */ close(): void; /** * @description Closes the ssh socket if still connected */ disconnect(): void; /** * * @param cmd Command string to execute * @param options Command channel execution options * @description Opens a ssh channel to handle a command execution by yourself * @returns A promise that resolves when the command begins execution and the promise provides you with the SshChannel to process the command output */ execChannel(cmd: string, options?: CmdChannelOptions): Promise<SshChannel>; /** * * @param cmd Command string to execute * @param options Command execution options * @description Opens an SSH channel to execute the command and resolves the promise as soon as the exit code is available for the executed command * @returns A promise that resolves when the command begins execution and the promise provides you the process some runtime, stdout, stderr and some exit data */ exec(cmd: string, options?: CmdExecOptions): Promise<SshChannelExit>; /** * * @description Opens a ssh shell channel to handle the shell by yourself * @returns A promise that resolves when the shell is started and the promise provides you with a session channel */ shellChannel(): Promise<ClientChannel>; /** * * @param pwd Inital path of the session * @param sudo Defines if commands should be prefied as sudo * @param timeoutMillis Default command timeout milliseconds * @returns The new created ExecSession object */ session(pwd: string, sudo?: boolean, timeoutMillis?: number): ExecSession; homeDir(): Promise<string>; /** * * @param cmd Command to check if it cmdExists * @description Function that checks if a spisific command exists on the remote ssh host * @returns True if command exists and false if not */ cmdExists(cmd: string): Promise<boolean>; cachedOsRelease: OsRelease | undefined; /** * * @description Resolves all releases files from '/etc/*-release' on the remove ssh host and maps them. Also tries to detect the distro name and version. * @param useCache The return value of this function get cached for the next function call. Set this to false to disable the caching. * @returns Returns an object that maps all values of all '/etc/*-release' files. */ fetchOsRelease(useCache?: boolean): Awaitable<OsRelease>; cachedApm: AbstractPackageManager | undefined; /** * @deprecated Check your self * @description Checks one of the predefined package mangers is installed (apt, dnf, yum or a custom one) and returns a abstract interface for that package manager. * @param useCache The return value of this function get cached for the next function call. Set this to false to disable the caching. * @throws Throws an error if the package manager cant be detected. * @returns The abstract interface of the hosts package manager (if found). */ getApm(useCache?: boolean): Awaitable<AbstractPackageManager>; /** * @experimental This function is experimental and may not be stable. * Creates a local server that tunnels incoming connections to a remote linux socket or host and port bind. * * You need to close the server to stop tunneling! * * This function creates a server that listens for incoming connections and forwards them to the remote SSH host. * * @param tunnelOptions - Options specifying remote linux socket or host and port details. * * @returns A promise that resolves to the created server that need to be closed. */ tunnelOut(tunnelOptions: SshTunnelOutOptions): Promise<net.Server>; } //# sourceMappingURL=SshHost.d.ts.map