Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.SFTP.Client

Feature notes: SFTP implementation notes

Classes, interfaces and records

classeSFTPFileAlreadyExists

inherits from Exception

Raised by the file-name GetFile overload when the local destination file already exists and the caller requested neither overwrite nor resume. It is a client-side download-collision signal only; it has no bearing on the remote SFTP server.

(no public members)

classTstSFTPClient — component reference

inherits from TstCustomProtoComponent

constructor Create(aOwner: TComponent); override;
Lifecycle only: creates the tSupportedStructure that later records the server's advertised extensions. The component is normally created by its owner/form-streaming, so an application rarely calls this directly. » member page
destructor Destroy; override;
Lifecycle only: releases the cached SFTP transport interface and frees the supported-extensions structure. Called automatically when the owner is destroyed. » member page
function Connect: iSFTPClientTransport;
Returns the shared SFTP transport, opening one on first use and caching it for reuse; every high-level method here calls it internally. An application can call it directly to obtain the low-level iSFTPClientTransport for protocol operations not wrapped by this component. » member page
function ConnectNew: iSFTPClientTransport;
Always opens a brand-new SFTP session over a fresh SSH channel (obtained from Transport as iSSHClient, or supplied via OnGetTransport) rather than reusing the cached one. Use it when a second, independent SFTP session is needed; raises eSFTPClientError if no channel can be obtained. » member page
function ChangeCurrentDir(const aDirName: string): Boolean;
Sets the client-side working directory used to resolve every relative path passed to the other methods, after verifying the target opens as a directory on the server; returns False if it does not. This "current directory" is a purely client-side convenience (SFTP itself is stateless about cwd) resolved locally via path combination. » member page
function RetrieveCurrentDir: string;
Returns the current client-side working directory string. It reports the locally tracked value set by ChangeCurrentDir and does not query the server for a canonical path. » member page
function GetFile(const aRemoteName : string; const aLocalName : string; aCanOverwrite: Boolean = False; aResume : Boolean = False) : Boolean; overload;
Downloads a remote file to a local file path. aCanOverwrite permits replacing an existing local file; aResume continues a partial download by appending (and, when both are set, relies on the server's md5-hash-handle extension to reconcile the overlap). Raises eSFTPFileAlreadyExists if the local file exists and neither flag is given. » member page
function GetFile(const aRemoteName: string; aLocalStrm : TStream; aResume : Boolean = False) : Boolean; overload;
Core download routine: streams a remote file into any TStream from its current position. With aResume it continues sequentially from that position, plain-reading only the remaining bytes. Full description »
procedure PutFile(const aSource : TStream; const aDestFile: string; const aAppend : Boolean = False); overload;
Core upload routine: writes a source stream to a remote file in requests of up to 128 KB, each at the offset in the remote file that equals its position in the stream. Full description »
procedure PutFile(const aSourceFile: string; const aDestFile : string; const aAppend : Boolean = False); overload;
Uploads a local file by name to a remote file, opening the local file read-shared and delegating to the stream overload above. » member page
function CmpFile(const aSource : TStream; const aDestFile: string; const aOffset : Int64; aLength : Integer) : Boolean; overload;
Compares a region (aOffset/aLength) of a local stream against the same region of a remote file via the server's md5-hash-handle extension, returning True when the MD5 hashes match. Used to verify an upload or decide whether a resumed transfer can be skipped. » member page
function CmpFile(const aSourceFile: string; const aDestFile : string; const aOffset : Int64; aLength : Integer) : Boolean; overload;
Compares a region of a local file (by name) against a remote file as above; raises if the server has not advertised the md5-hash-handle extension. » member page
function Size(const aFileName: string): Int64;
Returns the size in bytes of a remote file, by opening it and reading its size attribute. Convenience wrapper for a metadata-only stat. » member page
function List(const aDirectory: string = ''): iFileAttributesList;
Enumerates a remote directory (the current directory when aDirectory is empty) and returns the entries as an iFileAttributesList; the OnReadDir event also fires per entry as the listing is read. » member page
procedure MakeDir(const aDirName: string; const aAttrs : iFileAttributes = nil);
Creates a remote directory, optionally applying the supplied attributes. Raises on failure. » member page
procedure RemoveDir(const aDirName: string);
Removes a remote directory. Raises on failure. » member page
procedure Rename(const aSourceFile, aDestFile : string; aFlags : tRenameFlags = []);
Renames or moves a remote file. aFlags requests optional semantics such as overwrite/atomic replacement where the negotiated protocol version supports them. Raises on failure. » member page
procedure Delete(const aFilename: string);
Deletes a remote file. Raises on failure. » member page
property ServerSupported: tSupportedStructure read fServerSupported;
Read-only view of the extensions/features the server advertised during the SFTP version exchange; it is populated as the transport connects. The component consults its ExtensionNames to gate optional features such as md5-hash-handle used by CmpFile and resumed GetFile. » member page
property Transport: TstCustomProtoComponent read fTransport write SetTransport;
The SSH client component that carries the SFTP session; the assigned component must support iSSHClient (a TstSSHClient), and assignment is rejected otherwise. Set this to the app's SSH client so Connect can open an SFTP channel over the established SSH connection. » member page
property OnGetTransport: tGetTransportEvent read fOnGetTransport write SetOnGetTransport;
Advanced wiring fired by ConnectNew to supply or override the SSH windowed channel used for the SFTP session. The handler receives the channel created from Transport (if any) and may replace it, or provide one when no Transport is set. Most applications leave this unassigned and rely on Transport. » member page
property OnReadDir: tDirListEvent read fOnReadDir write SetOnReadDir;
Fires once per directory entry as List (and the underlying ReadDir loop) enumerates a remote directory, delivering each filename and its attributes. Hook it to stream a directory listing to the UI as it arrives. » member page

Types (enumerations, sets, aliases)

proctGetTransportEvent

Signature of the OnGetTransport handler: lets the app supply or replace the SSH windowed channel that carries a new SFTP session (see ConnectNew).

  tGetTransportEvent = procedure (Sender    : TObject;
                              var aTransport: iSSHWindowedChannel) of object;

proctDirListEvent

Signature of the OnReadDir handler: invoked once per remote directory entry during a listing, delivering the filename and its parsed attributes.

  tDirListEvent = procedure (Sender     : TObject;
                       const aTransport : iSFTPTransport;
                       const aFileName  : string;
                       const aAttributes: iFileAttributes) of object;