Class SftpTransferOptions
Options for SftpClient's uploads and downloads.
public sealed class SftpTransferOptions
- Inheritance
-
SftpTransferOptions
- Inherited Members
Properties
- Filter
Chooses what UploadDirectoryAsync(string, string, SftpTransferOptions?, CancellationToken) and DownloadDirectoryAsync(string, string, SftpTransferOptions?, CancellationToken) transfer: called for each file and directory of the source tree with its path relative to the top directory and its attributes, it returns false to leave the entry out. A directory left out is neither created nor entered, so nothing below it is transferred (or passed to the filter). Null (the default) transfers everything. The single-file methods ignore it.
- MaxConcurrentFiles
How many files UploadDirectoryAsync(string, string, SftpTransferOptions?, CancellationToken) and DownloadDirectoryAsync(string, string, SftpTransferOptions?, CancellationToken) transfer at once over the same SFTP session (default 1: one after another; at most 64). Each file costs round trips of its own (open, attributes, close), so on a link with latency a tree of many small files moves several times faster with 4 to 16. It does not speed up a few large files, which already keep MaxRequestsInFlight requests in flight (Segments is for those). The single-file methods ignore it.
- MaxRequestsInFlight
How many reads or writes may be in flight at once (default 64, as OpenSSH's sftp). More helps on links with latency. It bounds the whole transfer: one file's reads or writes, or in a directory transfer with MaxConcurrentFiles above 1 those of all its files together, so at most this many, each of up to MaxReadLength or MaxWriteLength bytes, are held in memory at once.
- Overwrite
Replace an existing destination file (default true, as
sftp putandgetdo); otherwise it is an error.
- Preserve
Copy the source's modification and access times, and its permission bits (read, write and execute for the owner, the group and others), to the destination, as
sftp -pdoes. Permissions are copied only where the receiving side has Unix modes: a download to Windows keeps the times only, and an upload from Windows sends none. Unlike OpenSSH, setuid, setgid and the sticky bit are never copied, so a server cannot hand this machine a setuid file. An upload sets a file's attributes through its open handle before closing it, and a directory's without following a symbolic link (lsetstat@openssh.com, where the server has it), so another user who replaces either with a link meanwhile cannot have them applied to the link's target.
- Progress
Reports each file's progress: its path, the bytes transferred so far and its size, when known.
- Resume
Continue an interrupted transfer, as sftp's
regetandreputdo: the destination's existing bytes are taken as the source's first ones, and only the rest is sent; a destination larger than the source is an error. Nothing checks that the existing bytes match, so use it for the same file only. A failed download with this set keeps what arrived. Overrides Overwrite for an existing destination.
- Segments
How many parts of one file DownloadFileAsync(string, string, SftpTransferOptions?, CancellationToken) fetches, or UploadFileAsync(string, string, SftpTransferOptions?, CancellationToken) writes, at once, each over its own SFTP session on the same connection (default 1: one session). Each session is an SSH channel with its own flow-control window, and on OpenSSH its own
sftp-serverprocess, so on a link with high latency several segments move more than one session can: one session carries at most its 2 MiB window per round trip. It does not help where the bandwidth, or the server's single connection, is the limit. Files smaller than 1 MiB per segment use fewer segments; the server may allow fewer sessions (sshd'sMaxSessions, 10 by default), and then fewer are used. Ignored with Resume (only a sequential transfer leaves a prefix to resume from) and by DownloadAsync(string, Stream, SftpTransferOptions?, CancellationToken) and UploadAsync(Stream, string, SftpTransferOptions?, CancellationToken), which use a stream in order.
- SkipUnchanged
In UploadDirectoryAsync(string, string, SftpTransferOptions?, CancellationToken) and DownloadDirectoryAsync(string, string, SftpTransferOptions?, CancellationToken), leave a file alone when the destination already has a regular file of that name with the same size and modification time, as rsync's quick check does (default false). The single-file methods ignore it.
- SkipUnreadableDirectories
In UploadDirectoryAsync(string, string, SftpTransferOptions?, CancellationToken) and DownloadDirectoryAsync(string, string, SftpTransferOptions?, CancellationToken), leave out a subdirectory of the source tree that this user may not read, and go on with the rest (default false: the transfer fails with the error, as
cp -rstops). A remote directory qualifies when the server refuses its listing with PermissionDenied, a local one when this system refuses it (UnauthorizedAccessException). What was left out is in UnreadableDirectories. The single-file methods ignore it.
- TimeTolerance
How far apart the modification times may be for SkipUnchanged to take a file as unchanged, as rsync's
--modify-window(default zero: the same second). Set it when one side keeps coarser times than a second, so the times copied with Preserve come back rounded: 2 seconds for FAT and exFAT (USB drives, SD cards), and for SMB shares backed by them; a second for a server or share that rounds to the nearest second rather than dropping the fraction. Without it every file on such a file system is transferred again.