Skip to content

Class: ScpClient ​

A connected client. Create one with connect, close it with ScpClient.close or await using.

Properties ​

PropertyModifierTypeDescription
fsreadonlyRemoteFs | undefinedRemote filesystem operations. undefined when the connection uses SCP.
protocolreadonlyActiveProtocolThe protocol transfers use on this connection.
remoteOsreadonlyRemoteOsPath flavour and quoting rules of the server, as passed to connect.
sftpreadonlySFTPWrapper | undefinedThe raw ssh2 SFTP session, for advanced use. undefined when the connection uses SCP.
sshreadonlyClientThe underlying ssh2 client, for advanced use such as running commands.

Accessors ​

closed ​

Get Signature ​

ts
get closed(): boolean;

true once the connection is closed, by close or by the network.

Returns ​

boolean

Methods ​

[asyncDispose]() ​

ts
asyncDispose: Promise<void>;

Closes the connection at the end of an await using block.

Returns ​

Promise<void>


close() ​

ts
close(): Promise<void>;

Closes the connection. Safe to call more than once.

Returns ​

Promise<void>


download() ​

ts
download(
   remotePath, 
   localPath, 
   options?
): Promise<TransferResult>;

Copies a remote file, or a directory with recursive: true, to localPath. The destination is exact and local parent directories are created.

Parameters ​

ParameterType
remotePathstring
localPathstring
optionsTransferOptions

Returns ​

Promise<TransferResult>


readFile() ​

ts
readFile(remotePath, options?): Promise<Buffer<ArrayBufferLike>>;

Reads a whole remote file into memory. Works over SFTP and SCP.

Parameters ​

ParameterType
remotePathstring
optionsReadFileOptions

Returns ​

Promise<Buffer<ArrayBufferLike>>


upload() ​

ts
upload(
   localPath, 
   remotePath, 
   options?
): Promise<TransferResult>;

Copies a local file, or a directory with recursive: true, to remotePath. The destination is exact: upload('dist', '/www') makes /www mirror dist. The remote parent directory must exist.

Parameters ​

ParameterType
localPathstring
remotePathstring
optionsTransferOptions

Returns ​

Promise<TransferResult>


writeFile() ​

ts
writeFile(
   remotePath, 
   data, 
   options?
): Promise<void>;

Writes a string, bytes or a stream to a remote file. Works over SFTP and SCP.

Parameters ​

ParameterType
remotePathstring
datastring | Uint8Array<ArrayBufferLike> | Readable
optionsWriteFileOptions

Returns ​

Promise<void>

Released under the MIT License.