ddn.net.sftp.transfer

Bounded pipelined SFTP transfer engine.

SftpDownload schedules multiple positioned READ requests within explicit request-count and byte budgets, reassembles out-of-order and short responses, fills holes left by short reads, and hands ordered data to a caller sink that may accept partial writes.

SftpUpload symmetrically pipelines positioned WRITE requests, pulling bytes from a caller source and tracking every server acknowledgment. Completion means every write was acknowledged; use the capability-checked fsync extension for durability and close the handle afterwards. Accepted data (handed to the protocol) and acknowledged data (confirmed by the server) are reported separately.

Both engines never block and never reenter the caller: progress happens through SftpDownload.pump / SftpUpload.pump, driven alongside the owning client and session pumps.

The remote file is not snapshotted. A file that shrinks while a download runs surfaces as an explicit error rather than silently truncated output; an interrupted upload leaves explicitly uncertain completion, and cleanup closes the handle without replaying writes.

Types 5

Tuning bounds for one pipelined transfer.

The engine never exceeds the client's outstanding-request limit and always clamps the chunk size to the client's effective negotiated limits, regardless of the values configured here.

Fields
uint chunkSizeRequested chunk size in bytes; zero selects the client's effective chunk size
uint maxInFlightMaximum simultaneous outstanding requests
ulong byteBudgetMaximum bytes held as in-flight, reordered, or undelivered transfer state
aliasSftpDataSink = size_t delegate(scope const(ubyte)[] data)

Receives ordered download data. Returning a count smaller than the provided length applies backpressure; the remainder is retained inside the engine's byte budget and redelivered on later pumps.

aliasSftpDataSource = size_t delegate(scope ubyte[] destination)

Produces ordered upload data into the provided buffer. Returning zero marks the source exhausted; partial production is legal and the engine asks again on later pumps.

A bounded pipelined download from an open file handle.

The caller owns the handle; the engine only issues positioned READ requests against it. Cancelling stops scheduling and discards reordered data, but the wire request IDs stay reserved in the client until their late replies arrive.

Fields
private SftpClient client_
private const(ubyte)[] handle_
private ulong length_
private SftpDataSink sink_
private SftpTransferOptions options_
private uint chunk_
private ulong expected_
private ulong stopOffset_
private ulong issueOffset_
private ulong eofOffset_
private ulong inflightBytes_
private ulong delivered_
private ulong peakBufferedBytes_
private const(ubyte)[] pendingDelivery_
private const(ubyte)[][ulong] buffered_
private ulong bufferedBytes_
private Hole[] holes_
private Slot[] outstanding_
private SftpProgress progress_
private SftpError error_
Methods
SftpProgress progress() @property constReturns: current progress.
bool done() @property constReturns: true when the transfer reached a terminal state.
bool succeeded() @property constReturns: true when the transfer completed successfully.
SftpError error() @property constReturns: the error when failed.
ulong delivered() @property constReturns: ordered bytes accepted by the sink so far.
ulong bufferedBytes() @property constReturns: bytes currently buffered as undelivered transfer state.
ulong peakBufferedBytes() @property constReturns: the peak of bufferedBytes plus in-flight bytes.
uint inFlightCount() @property constReturns: the number of outstanding READ requests.
void pump()Advances the download: moves channel bytes, processes completed reads, delivers to the sink, and schedules further requests.
void cancel()Cancels the transfer. Outstanding request interest is cancelled and reordered data is discarded; the handle remains open.
private void processCompletions()
private void store(ulong offset, const(ubyte)[] data)
private void deliverPending()
private void schedule()
private void commitRange(ulong start, uint length)
private ulong stopLimit()
private bool peekReadRange(out ulong start, out uint length)
private void addHole(ulong start, ulong stop)
private void checkCompletion()
private void fail(string message)
Constructors
this(SftpClient client, const(ubyte)[] handle, ulong length, SftpDataSink sink, SftpTransferOptions options = SftpTransferOptions.init)Constructs a download.
Nested Templates
Slot
Hole
Fields
private SftpClient client_
private const(ubyte)[] handle_
private SftpDataSource source_
private SftpTransferOptions options_
private uint chunk_
private ulong writeOffset_
private ulong pulled_
private ulong acknowledged_
private ulong outstandingBytes_
private ulong peakOutstandingBytes_
private bool sourceExhausted_
private Slot[] outstanding_
private SftpProgress progress_
private SftpError error_
Methods
SftpProgress progress() @property constReturns: current progress.
bool done() @property constReturns: true when the transfer reached a terminal state.
bool succeeded() @property constReturns: true when every write was acknowledged.
SftpError error() @property constReturns: the error when failed.
ulong accepted() @property constReturns: bytes accepted from the source into the protocol.
ulong acknowledged() @property constReturns: bytes the server acknowledged as written.
ulong bufferedBytes() @property constReturns: unacknowledged bytes currently outstanding.
ulong peakBufferedBytes() @property constReturns: the peak of bufferedBytes.
uint inFlightCount() @property constReturns: the number of outstanding WRITE requests.
void pump()Advances the upload: moves channel bytes, records acknowledgments, and schedules further writes from the source.
void cancel()Cancels the transfer. Outstanding request interest is cancelled; completion of the already-written prefix stays uncertain until the caller closes the handle.
private void processAcks()
private void schedule()
private void checkCompletion()
private void fail(string message)
Constructors
this(SftpClient client, const(ubyte)[] handle, SftpDataSource source, SftpTransferOptions options = SftpTransferOptions.init)Constructs an upload starting at offset zero.
this(SftpClient client, const(ubyte)[] handle, ulong offset, SftpDataSource source, SftpTransferOptions options = SftpTransferOptions.init)Constructs an upload starting at an explicit offset.
Nested Templates
Slot