pure-js-sftp
Version:
A pure JavaScript SFTP client with revolutionary RSA-SHA2 compatibility fixes. Zero native dependencies, built on ssh2-streams with 100% SSH key support.
226 lines • 5.15 kB
TypeScript
/**
* SSH Protocol Types and Interfaces
*/
export declare const SFTP_VERSION = 3;
export declare enum SFTP_MSG {
INIT = 1,
VERSION = 2,
OPEN = 3,
CLOSE = 4,
READ = 5,
WRITE = 6,
LSTAT = 7,
FSTAT = 8,
SETSTAT = 9,
FSETSTAT = 10,
OPENDIR = 11,
READDIR = 12,
REMOVE = 13,
MKDIR = 14,
RMDIR = 15,
REALPATH = 16,
STAT = 17,
RENAME = 18,
READLINK = 19,
SYMLINK = 20,
STATUS = 101,
HANDLE = 102,
DATA = 103,
NAME = 104,
ATTRS = 105,
EXTENDED = 200,
EXTENDED_REPLY = 201
}
export declare enum SFTP_STATUS {
OK = 0,
EOF = 1,
NO_SUCH_FILE = 2,
PERMISSION_DENIED = 3,
FAILURE = 4,
BAD_MESSAGE = 5,
NO_CONNECTION = 6,
CONNECTION_LOST = 7,
OP_UNSUPPORTED = 8
}
export declare enum SFTP_OPEN_FLAGS {
READ = 1,
WRITE = 2,
APPEND = 4,
CREAT = 8,
TRUNC = 16,
EXCL = 32
}
export declare enum SFTP_ATTR {
SIZE = 1,
UIDGID = 2,
PERMISSIONS = 4,
ACMODTIME = 8,
EXTENDED = 2147483648
}
export interface SSHConfig {
host: string;
port?: number;
username: string;
password?: string;
privateKey?: string | Buffer;
passphrase?: string;
timeout?: number;
keepaliveInterval?: number;
algorithms?: AlgorithmConfig;
debug?: boolean;
}
export interface AlgorithmConfig {
kex?: string[];
hostKey?: string[];
cipher?: string[];
mac?: string[];
compress?: string[];
}
export interface SSHPacket {
type: number;
payload: Buffer;
}
export interface KEXInitMessage {
cookie: Buffer;
kex_algorithms: string[];
server_host_key_algorithms: string[];
encryption_algorithms_client_to_server: string[];
encryption_algorithms_server_to_client: string[];
mac_algorithms_client_to_server: string[];
mac_algorithms_server_to_client: string[];
compression_algorithms_client_to_server: string[];
compression_algorithms_server_to_client: string[];
languages_client_to_server: string[];
languages_server_to_client: string[];
first_kex_packet_follows: boolean;
reserved: number;
}
export interface AuthContext {
username: string;
service: string;
method: string;
authenticated: boolean;
}
export interface ChannelInfo {
id: number;
remoteId: number;
windowSize: number;
maxPacketSize: number;
type: string;
state: ChannelState;
}
export declare enum ChannelState {
CLOSED = 0,
OPEN = 1,
EOF_SENT = 2,
EOF_RECEIVED = 3,
CLOSE_SENT = 4,
CLOSE_RECEIVED = 5
}
export interface SFTPPacket {
type: SFTP_MSG;
id?: number | undefined;
payload: Buffer;
}
export interface SFTPStatus {
code: SFTP_STATUS;
message: string;
language?: string;
}
export interface SFTPHandle {
handle: Buffer;
path?: string;
flags?: number;
}
export interface FileAttributes {
flags: number;
size?: number;
uid?: number;
gid?: number;
permissions?: number;
atime?: number;
mtime?: number;
extended?: {
[key: string]: string;
};
isFile(): boolean;
isDirectory(): boolean;
isSymbolicLink(): boolean;
isBlockDevice(): boolean;
isCharacterDevice(): boolean;
isFIFO(): boolean;
isSocket(): boolean;
}
export interface DirectoryEntry {
filename: string;
longname: string;
attrs: FileAttributes;
}
export interface FileStats {
mode: number;
uid: number;
gid: number;
size: number;
atime: Date;
mtime: Date;
isFile(): boolean;
isDirectory(): boolean;
isBlockDevice(): boolean;
isCharacterDevice(): boolean;
isSymbolicLink(): boolean;
isFIFO(): boolean;
isSocket(): boolean;
}
export interface FileInfo {
type: 'd' | '-' | 'l';
name: string;
size: number;
modifyTime: Date;
accessTime: Date;
rights: {
user: string;
group: string;
other: string;
};
owner: number;
group: number;
}
export declare enum ConnectionState {
DISCONNECTED = 0,
CONNECTING = 1,
VERSION_EXCHANGE = 2,
KEY_EXCHANGE = 3,
AUTHENTICATION = 4,
AUTHENTICATED = 5,
SFTP_INIT = 6,
READY = 7,
DISCONNECTING = 8
}
export declare class SSHError extends Error {
code?: string | undefined;
level?: "client" | "protocol" | "sftp" | undefined;
constructor(message: string, code?: string | undefined, level?: "client" | "protocol" | "sftp" | undefined);
}
export declare class SFTPError extends Error {
code?: SFTP_STATUS | undefined;
path?: string | undefined;
constructor(message: string, code?: SFTP_STATUS | undefined, path?: string | undefined);
}
export interface StreamOptions {
flags?: string;
encoding?: BufferEncoding;
mode?: number;
autoClose?: boolean;
start?: number;
end?: number;
highWaterMark?: number;
}
export interface TransferOptions {
concurrency?: number;
chunkSize?: number;
mode?: number;
encoding?: BufferEncoding;
debug?: boolean;
progress?: (transferred: number, total: number, fsize: number) => void;
}
//# sourceMappingURL=types.d.ts.map