ddn.net.sftp.client
SFTP client (draft-ietf-secsh-filexfer-02, protocol version 3).
A non-blocking SFTP client operating on any SshChannel from the DDN core API. The client depends only on the channel interface, never on a concrete SSH implementation or a cryptographic library; applications wire an opened subsystem channel from any transport.
Driving model: construct on a channel, call pump to move bytes and advance pending operations, and poll the returned operation objects. Every potentially-blocking step reports progress instead of blocking.
Types 9
SFTP client limits from the support matrix.
Raised for SFTP client violations: framing errors, unexpected responses, or unsupported versions.
this(string msg, string file = __FILE__, size_t line = __LINE__)Constructs an SFTP exception.Progress of an SFTP operation.
Typed SFTP operation error.
uint codeSFTP status code (0 when the failure is local)string messageHuman-readable descriptionSFTP version 3 client on a caller-supplied channel.
The client is single-threaded and driven by explicit pumping. The channel belongs to the caller; closing the channel terminates all pending operations.
private SshChannel channel_private ubyte[] readBuffer_private ubyte[] writeBuffer_private size_t writeOffset_private bool initSent_private bool initialized_private uint serverVersion_private string[string] extensions_private SftpServerLimits negotiated_private bool limitsKnown_private SftpError terminalError_private bool immediateWork_private uint nextId_private SftpPending[uint] pending_private SftpHandleRecord[] handles_private const(ubyte)[][] orphanHandles_uint outstandingRequests() @property constReturns: the number of request IDs currently reserved by outstanding or cancelled-but-undrained operations.bool immediateWork() @property constReturns: whether the last pump stopped at its work quota while internal or immediately readable work remained.bool pump() @trustedAdvances the protocol: sends INIT when needed, moves channel bytes, and dispatches completed server packets.SftpOperation!(const(ubyte)[]) open(const(ubyte)[] path, uint flags,
SftpAttrs attrs = SftpAttrs.init)Opens or creates a remote file.SftpOperation!bool close(const(ubyte)[] handle)Closes a file or directory handle.SftpOperation!(const(ubyte)[]) read(const(ubyte)[] handle,
ulong offset, uint length)Reads data from a file handle at a position.SftpOperation!bool write(const(ubyte)[] handle, ulong offset,
const(ubyte)[] data)Writes data to a file handle at a position.SftpOperation!(const(ubyte)[]) opendir(const(ubyte)[] path)Opens a directory for listing.SftpOperation!(SftpName[]) readdir(const(ubyte)[] handle)Reads the next batch of directory entries.SftpOperation!bool remove(const(ubyte)[] path)Removes a file.SftpOperation!bool mkdir(const(ubyte)[] path,
SftpAttrs attrs = SftpAttrs.init)Creates a directory.SftpOperation!bool rmdir(const(ubyte)[] path)Removes a directory.SftpOperation!(immutable(ubyte)[]) realpath(const(ubyte)[] path)Canonicalizes a path.SftpOperation!bool rename(const(ubyte)[] oldPath,
const(ubyte)[] newPath)Renames a file or directory.SftpOperation!(immutable(ubyte)[]) readlink(const(ubyte)[] path)Reads a symlink target.SftpOperation!bool symlink(const(ubyte)[] targetPath,
const(ubyte)[] linkPath,
SftpSymlinkOrder order = SftpSymlinkOrder.openssh)Creates a symlink.SftpOperation!SftpServerLimits queryLimits()Queries the server's transfer limits through limits@openssh.com version 1.SftpOperation!bool posixRename(const(ubyte)[] oldPath,
const(ubyte)[] newPath)Renames a path with POSIX replace semantics through posix-rename@openssh.com version 1.SftpOperation!bool fsync(const(ubyte)[] handle)Flushes written data of an open handle to stable storage through fsync@openssh.com version 1.SftpOperation!SftpStatVfs statvfs(const(ubyte)[] path)Queries filesystem information for a path through statvfs@openssh.com version 2.SftpOperation!SftpStatVfs fstatvfs(const(ubyte)[] handle)Queries filesystem information for an open handle through fstatvfs@openssh.com version 2.SftpOperation!bool hardlink(const(ubyte)[] oldPath,
const(ubyte)[] newPath)Creates a hard link through hardlink@openssh.com version 1.SftpOperation!bool copyData(const(ubyte)[] readHandle, ulong readOffset,
ulong readLength, const(ubyte)[] writeHandle, ulong writeOffset)Copies data server-side between two open handles through the copy-data extension version 1 (note: no vendor suffix in the extension name).uint effectiveReadChunk() const @safe pure nothrowReturns: the maximum READ data length local and negotiated limits allow; server zero-limits leave the local bound in effect.uint effectiveWriteChunk(size_t handleLength) const @safe pure nothrowParams: handleLength = Length of the handle used in WRITE requests.SftpOperation!SftpAttrs stat(const(ubyte)[] path)Retrieves attributes for a path while following symbolic links.SftpOperation!SftpAttrs lstat(const(ubyte)[] path)Retrieves attributes for a path without following symbolic links.SftpOperation!SftpAttrs fstat(const(ubyte)[] handle)Retrieves attributes for an open handle.SftpOperation!bool setstat(const(ubyte)[] path, SftpAttrs attrs)Updates attributes for a path.SftpOperation!bool fsetstat(const(ubyte)[] handle, SftpAttrs attrs)Updates attributes for an open handle.SftpHandleRecord handleRecordFor(const(ubyte)[] handle)Finds the tracking record for a server handle.SftpHandleRecord requireUsableHandle(const(ubyte)[] handle)Rejects work submitted after close and returns tracking state for handles opened by this client. Unknown handles remain supported.SftpHandleRecord recordHandle(const(ubyte)[] handle)Returns existing handle state or creates a locally bounded record.ulong effectiveHandleLimit() constReturns: effective local and negotiated open-handle limit.size_t activeHandleCount() constReturns: records that may still represent open remote handles.size_t ownedHandleCount() constReturns: local handle ownership including deferred orphan cleanup.SftpOperation!bool sendForStatusTracked(const(ubyte)[] payload,
SftpHandleRecord record)Sends a status-expecting request and registers it under a handle.SftpOperation!bool sendForStatusTracked(const(ubyte)[] payload,
SftpHandleRecord[] records)Sends a status request tracked against every participating handle.void retireTrackedId(uint id, SftpError error)Retires a completed request from its handle record and releases a pending barrier close when the handle drains.void releaseCloseIfDrained(SftpHandleRecord record,
bool failWhenBlocked = false)Sends the queued close once every tracked operation on the handle finished. Earlier operation failure is reported only after the wire CLOSE response, so cleanup is never skipped.bool hasDrainedClose() constReturns: whether a close is ready for immediate local submission.void removeHandleRecord(SftpHandleRecord record)Removes a handle record after its close completed.void queueOrphanClose(const(ubyte)[] orphanHandle)Sends a best-effort close for a handle whose owning operation was cancelled before its reply arrived.bool canQueueOrphanClose() constReturns: whether the next orphan CLOSE fits request/output limits.void ensureInitQueued()SftpOperation!bool sendForStatus(const(ubyte)[] payload)SftpOperation!(const(ubyte)[]) sendForHandle(
const(ubyte)[] payload)SftpOperation!(SftpName[]) sendNames(const(ubyte)[] payload,
bool isReaddir, SftpHandleRecord record = null)SftpOperation!(immutable(ubyte)[]) sendSingleName(
const(ubyte)[] payload)SftpOperation!SftpAttrs pathAttrs(ubyte type,
const(ubyte)[] path)SftpOperation!SftpAttrs sendForAttrs(const(ubyte)[] payload,
SftpHandleRecord record = null)SftpOperation!SftpServerLimits sendForLimits(
const(ubyte)[] payload)SftpOperation!SftpStatVfs sendForStatVfs(
const(ubyte)[] payload, SftpHandleRecord record = null)void requireExtension(SftpExtensionName name,
string expectedVersion = "1")uint send(const(ubyte)[] payload)uint allocateRequestId()void queueBytes(const(ubyte)[] bytes)void failAll(string message)void dispatch(const(ubyte)[] payload)void handleVersion(SftpReader reader)this(SshChannel channel)Constructs a client on an opened channel.Bookkeeping for one open server handle.
Tracks the request IDs issued against the handle so a barrier close waits for their outcomes, and carries the close operation returned to the caller while that wait lasts.
const(ubyte)[] handleuint[] pendingIdsSftpOperation!bool closeOperationbool closingbool closeSubmittedbool closeUncertainbool closedSftpError priorErrorthis(const(ubyte)[] serverHandle)Constructs a record for a freshly returned handle.What a pending operation expects from its response.
Internal pending record carrying response data to the typed operation.
private Object operation_SftpPendingKind kindSftpStatusCode statusCodestring statusMessageconst(ubyte)[] handleValueconst(ubyte)[] dataValueSftpName[] namesValueSftpAttrs attrsValueSftpServerLimits limitsValueSftpStatVfs statvfsValueuint expectedDataLengthSftpHandleRecord[] ownerRecordsSftpHandleRecord closesRecordbool operationAlreadyTerminal()Returns: whether the operation was already terminal before the reply arrived (a cancelled attempt whose handle leaked).SftpError operationError()Returns: an existing cancellation/failure on the public operation.void finish()Moves the collected response into the typed operation.void finishStatus()void requireKind(SftpPendingKind expected, string response) constthis(Object operation)Constructs a pending record.