title: “Resumable Transfers with ssh2-sftp-client” tags:
- WebShell slug: ‘17038235’ date: 2025-03-21 10:46:13
I’ve used
ssh2-sftp-clientto implement terminal-side upload/download. Because it supports streams, I implemented chunked uploads/downloads with progress bars. But networks are unreliable and transfers can be interrupted, so resumable transfer is needed. Looking into the implementation, I found thatssh2-sftp-clientcan support resuming.
put/get Methods
The third parameter to put/get is options. It includes writeStreamOptions/readStreamOptions. Inspecting their definitions shows a start parameter, which indicates the byte offset to start from.
With start, resumable transfer becomes straightforward.
export interface ReadStreamOptions extends ReadableOptions {
flags?: OpenMode;
mode?: number;
start?: number;
end?: number;
autoClose?: boolean;
handle?: Buffer;
}
export interface WriteStreamOptions extends WritableOptions {
flags?: OpenMode;
mode?: number;
start?: number;
autoClose?: boolean;
handle?: Buffer;
encoding?: BufferEncoding;
}
Conceptual Implementation
Take upload as an example. After a successful transfer segment, record the last transferred byte offset on the client. If the network drops, the next attempt sets start to that offset and continues. In essence, resumable transfer is similar to chunked transfer.

