vael:ssh
Synchronous SSH command execution and native SFTP (conn.sftp.*) with
mandatory host-key verification.
Available in both vjs (vaeljs) and vjs-lite (vaeljs-lite) runtimes.
Enforces explicit host-key pinning via hostKey or in-memory knownHosts,
supports password, in-memory private-key, and explicit SSH agent
authentication (including agentSocket for Unix sockets and Windows OpenSSH
named pipes such as \\.\pipe\openssh-ssh-agent), and never reads user
~/.ssh/ configuration or identity files.
import ... from "vael:ssh"
vaeljs-core; vael-ssh (default) in vaeljs-lite-coreconn.sftp), and agentSocket (Unix sockets and Windows OpenSSH named pipes) on both vjs and vjs-lite.Example
Section titled “Example”import { connect } from "vael:ssh";
const conn = connect({ host: "127.0.0.1", port: 2222, username: "deploy", knownHosts: "[127.0.0.1]:2222 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI...", agent: true,});try { const res = conn.exec("uname -a"); console.log(res.status, res.stdout.byteLength); const entries = conn.sftp.readDir("/tmp"); console.log(entries.length);} finally { conn.close();}SshExecResultv0.0.0-alpha.0SshConnection.exec(command).SftpStatv0.0.0-alpha.2SshSftp.stat and SshSftp.readDir.SftpDirEntryv0.0.0-alpha.2SshSftp.readDir.SftpReadDirOptionsv0.0.0-alpha.2SshSftp.readDir.SftpMkdirOptionsv0.0.0-alpha.2SshSftp.mkdir.SftpUploadOptionsv0.0.0-alpha.2SshSftp.upload.SftpDownloadOptionsv0.0.0-alpha.2SshSftp.download.SftpTransferResultv0.0.0-alpha.2SshSftp.upload and SshSftp.download.SshSftpv0.0.0-alpha.2SshConnection.SshConnectionv0.0.0-alpha.0connect(options).SshErrorCodev0.0.0-alpha.0SshError.code (name = "SshError").SshHostTrustOptionsv0.0.0-alpha.0hostKey or knownHosts.SshAuthOptionsv0.0.0-alpha.0password, privateKey, or SSH agent (agent: true and/or agentSocket).SshConnectOptionsv0.0.0-alpha.0connect(options). Unknown keys throw TypeError.MAX_COMMAND_BYTESv0.0.0-alpha.0SshConnection.exec (64 KiB).MAX_OUTPUT_BYTESv0.0.0-alpha.0SshConnection.exec (8 MiB).DEFAULT_CONNECT_TIMEOUT_MSv0.0.0-alpha.015_000).DEFAULT_EXEC_TIMEOUT_MSv0.0.0-alpha.030_000).Functions
Section titled “Functions”connect
Section titled “connect”export function connect(options: SshConnectOptions): SshConnection;
Synchronously dial, verify host identity, authenticate, and return an
SshConnection.
Never reads ssh_config, identity files, or ~/.ssh/known_hosts.
| Name | Type | Description |
|---|---|---|
options | SshConnectOptions | Connection, mandatory host-trust, and authentication options. |
SshConnection — Authenticated SshConnection handle.TypeError— on invalid options or unknown option keys.RangeError— on out-of-range port or timeout values.Error— (name = "SshError") withcode: SshErrorCode.
import { connect } from "vael:ssh";
const conn = connect({ host: "10.0.0.5", username: "ops", hostKey: new Uint8Array(32), privateKey: new Uint8Array(64),});conn.close();Interfaces
Section titled “Interfaces”SshExecResult
Section titled “SshExecResult”export interface SshExecResult {
stdout: Uint8Array;
status: number;
}
Result returned by SshConnection.exec(command).
| Property | Type | Description | Since |
|---|---|---|---|
stdout | Uint8Array | Captured remote stdout bytes (at most MAX_OUTPUT_BYTES). Remote stderr is discarded. | v0.0.0-alpha.0 |
status | number | Remote exit status code. | v0.0.0-alpha.0 |
SftpStat
Section titled “SftpStat”export interface SftpStat {
readonly size: number;
readonly isFile: boolean;
readonly isDir: boolean;
readonly isSymlink: boolean;
readonly permissions: number | null;
readonly uid: number | null;
readonly gid: number | null;
readonly atime: number | null;
readonly mtime: number | null;
}
Remote file or directory metadata returned by SshSftp.stat and
SshSftp.readDir.
| Property | Type | Description | Since |
|---|---|---|---|
size readonly | number | File size in bytes (0 when omitted by the server). | v0.0.0-alpha.2 |
isFile readonly | boolean | Whether POSIX mode bits indicate a regular file. | v0.0.0-alpha.2 |
isDir readonly | boolean | Whether POSIX mode bits indicate a directory. | v0.0.0-alpha.2 |
isSymlink readonly | boolean | Whether POSIX mode bits indicate a symbolic link. | v0.0.0-alpha.2 |
permissions readonly | number | null | Raw POSIX st_mode permissions word when provided by the server, or null. | v0.0.0-alpha.2 |
uid readonly | number | null | Owning user ID when provided by the server, or null. | v0.0.0-alpha.2 |
gid readonly | number | null | Owning group ID when provided by the server, or null. | v0.0.0-alpha.2 |
atime readonly | number | null | Last access timestamp (Unix seconds) when provided by the server, or null. | v0.0.0-alpha.2 |
mtime readonly | number | null | Last modification timestamp (Unix seconds) when provided by the server, or null. | v0.0.0-alpha.2 |
SftpDirEntry
Section titled “SftpDirEntry”export interface SftpDirEntry {
readonly name: string;
readonly longName: string;
readonly stat: SftpStat;
}
One directory entry returned by SshSftp.readDir.
| Property | Type | Description | Since |
|---|---|---|---|
name readonly | string | Entry name (excluding "." and ".."). | v0.0.0-alpha.2 |
longName readonly | string | Long listing string supplied by the SFTP server. | v0.0.0-alpha.2 |
stat readonly | SftpStat | Entry metadata attributes. | v0.0.0-alpha.2 |
SftpReadDirOptions
Section titled “SftpReadDirOptions”export interface SftpReadDirOptions {
maxEntries?: number;
}
Options accepted by SshSftp.readDir.
| Property | Type | Description | Since |
|---|---|---|---|
maxEntries optional | number | Maximum number of directory entries to return (1..=100_000, default 100_000). | v0.0.0-alpha.2 |
SftpMkdirOptions
Section titled “SftpMkdirOptions”export interface SftpMkdirOptions {
mode?: number;
}
Options accepted by SshSftp.mkdir.
| Property | Type | Description | Since |
|---|---|---|---|
mode optional | number | POSIX permission bits (0..=0o7777) applied to the new directory. | v0.0.0-alpha.2 |
SftpUploadOptions
Section titled “SftpUploadOptions”export interface SftpUploadOptions {
maxBytes?: number;
overwrite?: boolean;
mode?: number;
followSymlinks?: boolean;
}
Options accepted by SshSftp.upload.
| Property | Type | Description | Since |
|---|---|---|---|
maxBytes optional | number | Maximum bytes allowed to transfer (1..=536_870_912, default 67_108_864). | v0.0.0-alpha.2 |
overwrite optional | boolean | Whether an existing remote file may be overwritten (default true). | v0.0.0-alpha.2 |
mode optional | number | Optional POSIX permission bits (0..=0o7777) applied to the remote file. | v0.0.0-alpha.2 |
followSymlinks optional | boolean | Whether symbolic links are followed on the local source path (default false). | v0.0.0-alpha.2 |
SftpDownloadOptions
Section titled “SftpDownloadOptions”export interface SftpDownloadOptions {
maxBytes?: number;
overwrite?: boolean;
}
Options accepted by SshSftp.download.
| Property | Type | Description | Since |
|---|---|---|---|
maxBytes optional | number | Maximum bytes allowed to transfer (1..=536_870_912, default 67_108_864). | v0.0.0-alpha.2 |
overwrite optional | boolean | Whether an existing local destination file may be overwritten (default true). | v0.0.0-alpha.2 |
SftpTransferResult
Section titled “SftpTransferResult”export interface SftpTransferResult {
readonly bytesTransferred: number;
}
Summary returned by SshSftp.upload and SshSftp.download.
| Property | Type | Description | Since |
|---|---|---|---|
bytesTransferred readonly | number | Total number of payload bytes transferred. | v0.0.0-alpha.2 |
SshSftp
Section titled “SshSftp”export interface SshSftp {
stat(remotePath: string): SftpStat;
readDir(remotePath: string, options?: SftpReadDirOptions): readonly SftpDirEntry[];
mkdir(remotePath: string, options?: SftpMkdirOptions): void;
remove(remotePath: string): void;
rmdir(remotePath: string): void;
upload(
localPath: string,
remotePath: string,
options?: SftpUploadOptions,
): SftpTransferResult;
download(
remotePath: string,
localPath: string,
options?: SftpDownloadOptions,
): SftpTransferResult;
}
Synchronous SFTP v3 client scoped to an authenticated SshConnection.
Pre-flight validation errors and SFTP protocol status errors
("VAEL_SSH_SFTP") leave the parent SshConnection open. Fatal transport,
session, or sftpTimeoutMs deadline errors close the connection.
SshSftp.stat
Section titled “SshSftp.stat”stat(remotePath: string): SftpStat;
Query metadata (following symbolic links) for a remote path.
| Name | Type | Description |
|---|---|---|
remotePath | string | Remote file or directory path (non-empty, max 4096 bytes, no NUL bytes). |
SftpStat — Remote metadata attributes.TypeError— on wrong argument count or non-stringremotePath.Error— (name = "SshError") withcode"VAEL_SSH_CLOSED","VAEL_SSH_ARGUMENT","VAEL_SSH_SFTP","VAEL_SSH_TIMEOUT","VAEL_SSH_IO","VAEL_SSH_SESSION", or"VAEL_SSH_INTERNAL".
SshSftp.readDir
Section titled “SshSftp.readDir”readDir(remotePath: string, options?: SftpReadDirOptions): readonly SftpDirEntry[];
List directory entries at remotePath (excluding "." and "..").
| Name | Type | Description |
|---|---|---|
remotePath | string | Remote directory path (non-empty, max 4096 bytes, no NUL bytes). |
options optional | SftpReadDirOptions | Optional directory listing limits. |
readonly SftpDirEntry[] — Array of directory entries and their metadata.TypeError— on invalid arguments or unknown option keys.RangeError— on out-of-rangemaxEntries.Error— (name = "SshError") withcode"VAEL_SSH_CLOSED","VAEL_SSH_ARGUMENT","VAEL_SSH_LIMIT","VAEL_SSH_SFTP","VAEL_SSH_TIMEOUT","VAEL_SSH_IO","VAEL_SSH_SESSION", or"VAEL_SSH_INTERNAL".
SshSftp.mkdir
Section titled “SshSftp.mkdir”mkdir(remotePath: string, options?: SftpMkdirOptions): void;
Create a remote directory at remotePath.
| Name | Type | Description |
|---|---|---|
remotePath | string | Remote directory path (non-empty, max 4096 bytes, no NUL bytes). |
options optional | SftpMkdirOptions | Optional POSIX directory permissions. |
voidTypeError— on invalid arguments or unknown option keys.RangeError— on out-of-rangemode.Error— (name = "SshError") withcode"VAEL_SSH_CLOSED","VAEL_SSH_ARGUMENT","VAEL_SSH_SFTP","VAEL_SSH_TIMEOUT","VAEL_SSH_IO","VAEL_SSH_SESSION", or"VAEL_SSH_INTERNAL".
SshSftp.remove
Section titled “SshSftp.remove”remove(remotePath: string): void;
Remove a remote file or symbolic link at remotePath.
| Name | Type | Description |
|---|---|---|
remotePath | string | Remote file or symlink path (non-empty, max 4096 bytes, no NUL bytes). |
voidTypeError— on wrong argument count or non-stringremotePath.Error— (name = "SshError") withcode"VAEL_SSH_CLOSED","VAEL_SSH_ARGUMENT","VAEL_SSH_SFTP","VAEL_SSH_TIMEOUT","VAEL_SSH_IO","VAEL_SSH_SESSION", or"VAEL_SSH_INTERNAL".
SshSftp.rmdir
Section titled “SshSftp.rmdir”rmdir(remotePath: string): void;
Remove an empty remote directory at remotePath.
| Name | Type | Description |
|---|---|---|
remotePath | string | Remote directory path (non-empty, max 4096 bytes, no NUL bytes). |
voidTypeError— on wrong argument count or non-stringremotePath.Error— (name = "SshError") withcode"VAEL_SSH_CLOSED","VAEL_SSH_ARGUMENT","VAEL_SSH_SFTP","VAEL_SSH_TIMEOUT","VAEL_SSH_IO","VAEL_SSH_SESSION", or"VAEL_SSH_INTERNAL".
SshSftp.upload
Section titled “SshSftp.upload”upload(
localPath: string,
remotePath: string,
options?: SftpUploadOptions,
): SftpTransferResult;
Upload a local file to remotePath over SFTP.
| Name | Type | Description |
|---|---|---|
localPath | string | Local source file path. |
remotePath | string | Remote destination file path (non-empty, max 4096 bytes, no NUL bytes). |
options optional | SftpUploadOptions | Optional transfer size, overwrite, mode, and symlink settings. |
SftpTransferResult — Transfer summary containing bytesTransferred.TypeError— on invalid arguments or unknown option keys.RangeError— on out-of-rangemaxBytesormode.Error— (name = "SshError") withcode"VAEL_SSH_CLOSED","VAEL_SSH_ARGUMENT","VAEL_SSH_LIMIT","VAEL_SSH_SFTP","VAEL_SSH_TIMEOUT","VAEL_SSH_IO","VAEL_SSH_SESSION", or"VAEL_SSH_INTERNAL".
SshSftp.download
Section titled “SshSftp.download”download(
remotePath: string,
localPath: string,
options?: SftpDownloadOptions,
): SftpTransferResult;
Download a remote file at remotePath to localPath over SFTP.
| Name | Type | Description |
|---|---|---|
remotePath | string | Remote source file path (non-empty, max 4096 bytes, no NUL bytes). |
localPath | string | Local destination file path. |
options optional | SftpDownloadOptions | Optional transfer size and overwrite settings. |
SftpTransferResult — Transfer summary containing bytesTransferred.TypeError— on invalid arguments or unknown option keys.RangeError— on out-of-rangemaxBytes.Error— (name = "SshError") withcode"VAEL_SSH_CLOSED","VAEL_SSH_ARGUMENT","VAEL_SSH_LIMIT","VAEL_SSH_SFTP","VAEL_SSH_TIMEOUT","VAEL_SSH_IO","VAEL_SSH_SESSION", or"VAEL_SSH_INTERNAL".
SshConnection
Section titled “SshConnection”export interface SshConnection {
readonly closed: boolean;
readonly sftp: SshSftp;
exec(command: string | Uint8Array): SshExecResult;
close(): void;
}
Synchronous, authenticated SSH command-execution and SFTP connection
returned by connect(options).
| Property | Type | Description | Since |
|---|---|---|---|
closed readonly | boolean | Whether this connection is closed and can no longer run commands or SFTP operations. | v0.0.0-alpha.0 |
sftp readonly | SshSftp | Synchronous SFTP v3 client bound to this connection. | v0.0.0-alpha.2 |
SshConnection.exec
Section titled “SshConnection.exec”exec(command: string | Uint8Array): SshExecResult;
Synchronously execute a single command on the remote host.
Blocks until exit status arrives and the session channel closes, or until
execTimeoutMs expires. Fatal transport/session/timeout/output-limit
errors close the connection; pre-flight validation errors leave it open.
| Name | Type | Description |
|---|---|---|
command | string | Uint8Array | UTF-8 string or raw bytes (max MAX_COMMAND_BYTES). |
SshExecResult — { stdout, status } result from the remote command.TypeError— on wrong argument type or arity.Error— (name = "SshError") withcode"VAEL_SSH_CLOSED","VAEL_SSH_LIMIT","VAEL_SSH_TIMEOUT","VAEL_SSH_IO","VAEL_SSH_SESSION", or"VAEL_SSH_INTERNAL".
import { connect } from "vael:ssh";
const conn = connect({ host: "127.0.0.1", username: "deploy", knownHosts: "127.0.0.1 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI...", password: "demo",});const res = conn.exec("id -u");console.log(res.status);conn.close();SshConnection.close
Section titled “SshConnection.close”close(): void;
Close the underlying socket. Idempotent; does not send an SSH disconnect
packet. Subsequent exec and sftp calls throw VAEL_SSH_CLOSED.
voidType Aliases
Section titled “Type Aliases”SshErrorCode
Section titled “SshErrorCode”export type SshErrorCode =
| "VAEL_SSH_ARGUMENT"
| "VAEL_SSH_HOST_KEY_REQUIRED"
| "VAEL_SSH_HOST_KEY"
| "VAEL_SSH_KNOWN_HOSTS"
| "VAEL_SSH_AUTH_METHOD"
| "VAEL_SSH_CREDENTIAL"
| "VAEL_SSH_AGENT"
| "VAEL_SSH_CONNECT"
| "VAEL_SSH_TIMEOUT"
| "VAEL_SSH_HANDSHAKE"
| "VAEL_SSH_AUTH"
| "VAEL_SSH_SESSION"
| "VAEL_SSH_LIMIT"
| "VAEL_SSH_CLOSED"
| "VAEL_SSH_IO"
/** SFTP protocol or remote filesystem error. @since 0.0.0-alpha.2 */
| "VAEL_SSH_SFTP"
| "VAEL_SSH_INTERNAL";
Error codes reported on SshError.code (name = "SshError").
"VAEL_SSH_SFTP" was added in 0.0.0-alpha.2.
SshHostTrustOptions
Section titled “SshHostTrustOptions”export type SshHostTrustOptions =
| {
/** Explicit SSH-format Ed25519 host public-key blob. @since 0.0.0-alpha.0 */
hostKey: Uint8Array;
/** Must be omitted when `hostKey` is provided. @since 0.0.0-alpha.0 */
knownHosts?: undefined;
}
| {
/** Must be omitted when `knownHosts` is provided. @since 0.0.0-alpha.0 */
hostKey?: undefined;
/** In-memory `known_hosts` host-key records. @since 0.0.0-alpha.0 */
knownHosts: string;
};
Mandatory host-trust pin: supply exactly one of hostKey or knownHosts.
SshAuthOptions
Section titled “SshAuthOptions”export type SshAuthOptions =
| {
/** Password credential. @since 0.0.0-alpha.0 */
password: string;
/** Must be omitted for password authentication. @since 0.0.0-alpha.0 */
privateKey?: undefined;
/** Must be omitted for password authentication. @since 0.0.0-alpha.0 */
passphrase?: undefined;
/** Must be omitted or `false` for password authentication. @since 0.0.0-alpha.0 */
agent?: false;
/** Must be omitted for password authentication. @since 0.0.0-alpha.2 */
agentSocket?: undefined;
}
| {
/**
* In-memory unencrypted PKCS#8 DER/PEM or OpenSSH (`openssh-key-v1`/PEM)
* private key bytes.
*
* @since 0.0.0-alpha.0
*/
privateKey: Uint8Array;
/** Optional passphrase for encrypted `openssh-key-v1` containers only. @since 0.0.0-alpha.0 */
passphrase?: string;
/** Must be omitted for key authentication. @since 0.0.0-alpha.0 */
password?: undefined;
/** Must be omitted or `false` for key authentication. @since 0.0.0-alpha.0 */
agent?: false;
/** Must be omitted for key authentication. @since 0.0.0-alpha.2 */
agentSocket?: undefined;
}
| {
/**
* Explicit opt-in to authenticate via the platform SSH agent after
* host-key verification (tries up to 16 identities).
*
* When `agentSocket` is omitted, uses `SSH_AUTH_SOCK` on Unix or the
* Windows OpenSSH agent named pipe (`\\.\pipe\openssh-ssh-agent`).
*
* @since 0.0.0-alpha.0
*/
agent: true;
/**
* Optional explicit Unix socket path or Windows OpenSSH named pipe
* (`\\.\pipe\openssh-ssh-agent`), max 4096 bytes. Overrides
* `SSH_AUTH_SOCK` on Unix and the default named pipe on Windows.
*
* @since 0.0.0-alpha.2
*/
agentSocket?: string;
/** Must be omitted for agent authentication. @since 0.0.0-alpha.0 */
password?: undefined;
/** Must be omitted for agent authentication. @since 0.0.0-alpha.0 */
privateKey?: undefined;
/** Must be omitted for agent authentication. @since 0.0.0-alpha.0 */
passphrase?: undefined;
}
| {
/**
* Optional explicit opt-in to authenticate via the platform SSH agent
* after host-key verification (tries up to 16 identities).
*
* When `agentSocket` is supplied, `agent` may be `true` or omitted;
* `agent: false` is rejected.
*
* @since 0.0.0-alpha.0
*/
agent?: true;
/**
* Explicit Unix socket path or Windows OpenSSH named pipe
* (`\\.\pipe\openssh-ssh-agent`), max 4096 bytes. Overrides
* `SSH_AUTH_SOCK` on Unix and the default named pipe on Windows.
*
* @since 0.0.0-alpha.2
*/
agentSocket: string;
/** Must be omitted for agent authentication. @since 0.0.0-alpha.0 */
password?: undefined;
/** Must be omitted for agent authentication. @since 0.0.0-alpha.0 */
privateKey?: undefined;
/** Must be omitted for agent authentication. @since 0.0.0-alpha.0 */
passphrase?: undefined;
};
Authentication method: supply exactly one of password, privateKey,
or SSH agent (agent: true and/or agentSocket).
SshConnectOptions
Section titled “SshConnectOptions”export type SshConnectOptions = {
/** Remote hostname or IP address. @since 0.0.0-alpha.0 */
host: string;
/** Remote TCP port (`1..=65535`, default `22`). @since 0.0.0-alpha.0 */
port?: number;
/** SSH username (max 256 bytes). @since 0.0.0-alpha.0 */
username: string;
/** Connect/handshake inactivity timeout in ms (`1..=120_000`, default `15_000`). @since 0.0.0-alpha.0 */
connectTimeoutMs?: number;
/** Per-command execution timeout in ms (`1..=600_000`, default `30_000`). @since 0.0.0-alpha.0 */
execTimeoutMs?: number;
/** Per-operation SFTP timeout in ms (`1..=600_000`, default `60_000`). @since 0.0.0-alpha.2 */
sftpTimeoutMs?: number;
} & SshHostTrustOptions &
SshAuthOptions;
Options accepted by connect(options). Unknown keys throw TypeError.
Constants
Section titled “Constants”MAX_COMMAND_BYTES
Section titled “MAX_COMMAND_BYTES”export const MAX_COMMAND_BYTES: 65536;
Maximum command byte length accepted by SshConnection.exec (64 KiB).
MAX_OUTPUT_BYTES
Section titled “MAX_OUTPUT_BYTES”export const MAX_OUTPUT_BYTES: 8388608;
Maximum captured stdout byte length returned by SshConnection.exec (8 MiB).
DEFAULT_CONNECT_TIMEOUT_MS
Section titled “DEFAULT_CONNECT_TIMEOUT_MS”export const DEFAULT_CONNECT_TIMEOUT_MS: 15000;
Default TCP/handshake connect timeout in milliseconds (15_000).
DEFAULT_EXEC_TIMEOUT_MS
Section titled “DEFAULT_EXEC_TIMEOUT_MS”export const DEFAULT_EXEC_TIMEOUT_MS: 30000;
Default per-command execution timeout in milliseconds (30_000).
