More .NET components

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.

CSharp

// 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);

VisualBasic

' 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 statvfs@openssh.com extension.

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:

CSharp

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

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

// connect to server
sftp.Connect(hostname);

VisualBasic

' initialize client class
Dim sftp = New Sftp()

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

' connect to server
sftp.Connect(hostname)

Large file support #

BlockMode 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.