Rebex SFTP

SFTP and SCP client .NET library

Download 30-day free trial Buy from $349
More .NET libraries

Back to feature list...

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

Buffered data commit (fsync) 

On servers that support the fsync@openssh.com 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
sftp.Connect(hostname);
' initialize client class
Dim sftp = New Sftp()

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

' connect to server
sftp.Connect(hostname)

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 basic stream-based API or advanced 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.

Stream-based API 

Rebex SFTP provides access to remote files using .NET's System.IO.Stream object. It makes it possible to work with remote SFTP files as if they were stored locally.

GetDownloadStream() provides seekable, read-only stream:

// get read-only stream for download
using (var stream = sftp.GetDownloadStream("/MyData/file.txt"))
{
    // read data from the stream
    // (and/or seek within the stream)
    // ...
    int n = stream.Read(buffer, 0, buffer.Length);
}
' get read-only stream for download
Using stream = sftp.GetDownloadStream("/MyData/file.txt")
    ' read data from the stream
    ' (and/or seek within the stream)
    ' ...
    Dim n As Integer = stream.Read(buffer, 0, buffer.Length)
End Using

GetUploadStream() provides seekable, write-only stream (trims existing file):

// get write-only stream for upload (trims existing file)
using (var stream = sftp.GetUploadStream("/MyData/file.txt"))
{
    // write data to the stream
    // (and/or seek within the stream)
    // ...
    stream.Write(data, 0, data.Length);
}
' get write-only stream for upload (trims existing file)
Using stream = sftp.GetUploadStream("/MyData/file.txt")
    ' write data to the stream
    ' (and/or seek within the stream)
    ' ...
    stream.Write(data, 0, data.Length)
End Using

GetStream() can provide seekable, read/write stream depending on the passed arguments. It can be used to work with remote files in a way that corresponds to using System.IO.FileStream locally:

// get seekable, read/write stream representing the file
using (var stream = sftp.GetStream("/MyData/file.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
    // work with the stream as usual
    // ...
}
' get seekable, read/write stream representing the file
Using stream = sftp.GetStream("/MyData/file.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite)
    ' work with the stream as usual
    ' ...
End Using

Back to feature list...