Advanced file transfer operations

Disk free space and other drive information 

To get information about the file system (or disk drive) such as available free space, use GetFileSystemInfo method.

// get file system information
SftpFileSystemInfo info = sftp.GetFileSystemInfo("/");

// display file system information
Console.WriteLine("Total space: {0}", info.TotalSpace);
Console.WriteLine("Free space available: {0}", info.FreeSpace);
Console.WriteLine("Free space available to user: {0}", info.FreeSpaceForUser);
Console.WriteLine("File system ID: {0}", info.FileSystemId);
Console.WriteLine("Read-only file system: {0}", info.IsReadOnly);
Console.WriteLine("Block size: {0}", info.BlockSize);
' get file system information
Dim info As SftpFileSystemInfo = sftp.GetFileSystemInfo("/")

' display file system information
Console.WriteLine("Total space: {0}", info.TotalSpace)
Console.WriteLine("Free space available: {0}", info.FreeSpace)
Console.WriteLine("Free space available to user: {0}", info.FreeSpaceForUser)
Console.WriteLine("File system ID: {0}", info.FileSystemId)
Console.WriteLine("Read-only file system: {0}", info.IsReadOnly)
Console.WriteLine("Block size: {0}", info.BlockSize)

Note: This functionality only works with servers that support space-available or extension.

Buffered data commit (fsync) 

On servers that support the extension (such as OpenSSH), use Settings.EnableFileSync property to specify whether to commit buffered data to disk once a whole file has been uploaded.

ZLIB transfer compression 

SFTP protocol supports ZLIB compression to speed up data transfers and communication. This is particularly useful when transferring highly compressible files such as text files or sparse files. However, it can slow down the transfer speed a bit less compressible files such as multimedia or already-compressed files.

To enable compression, set Settings.SshParameters.Compression to true before connecting to the server:

// initialize client class
var sftp = new Sftp();

// enable transfer compression
sftp.Settings.SshParameters.Compression = true;

// connect to server
' initialize client class
Dim sftp = New Sftp()

' enable transfer compression
sftp.Settings.SshParameters.Compression = True

' connect to server

Large file support 

SFTP supports very large files - the theoretical maximum file size supported by the SFTP protocol is 2^63 bytes, which is 9,223,372,036,854,775,807, or 9,223,372 TB.

However, in practice, the maximum file size might be limited by the underlying filesystem. For example, FAT16's maximum file size is 2GB, FAT32's limit is 4GB. Check out this table for other filesystems.

But is it possible to transfer files larger than 4GB even when the local filesystem can't store them?

Actually, it is - you can use the stream-based API, which makes it possible to develop a custom stream to work around the filesystem's limitation (by splitting data into multiple smaller files, for example).

Simultaneous operations 

SFTP supports multiple simultaneous operations over a single SFTP session. This means it's possible to start multiple asynchronous methods on a single Sftp instance (once connected) - they will all run simultaneously. It's possible to call multiple synchronous methods from several threads as well.