Table of Contents

Property MaxConcurrentFiles

Namespace
SshSharp.Sftp
Assembly
SshSharp.dll

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.

public int MaxConcurrentFiles { get; init; }

Property Value

int

Remarks

The files share the transfer's MaxRequestsInFlight reads or writes rather than take that many each, so the memory the transfer holds does not grow with this setting: at most MaxRequestsInFlight times the read or write length (64 × 32 KiB by default, or 64 × 255 KiB with OpenSSH's limits, about 16 MiB), plus a 64 KiB local file buffer for each file in flight. Opening, closing and setting attributes add about one small request for each file in flight.

A directory is created before any file goes into it, and directories are created several at a time. With Preserve, directories get their times and permissions once every file is in, the deepest first. When the server announces MaxOpenHandles, fewer files are transferred at once if needed, keeping a handle free for listings.

The first failure cancels the files still in flight and is the exception the transfer throws. A cancelled file is left as a failed single-file transfer leaves it: a download is deleted (unless Resume is set), an upload keeps what was written. Progress reports each file's progress as before, the files' reports interleaved but never made at the same time.