The Maverick.NET SSH API

SFTPClient Class

Implements a Secure File Transfer (SFTP) client and which provides working directory management with the remote server.

For a list of all members of this type, see SFTPClient Members.

System.Object
   Maverick.SFTP.SFTPClient

[Visual Basic]
Public Class SFTPClient
[C#]
public class SFTPClient

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

SFTP was designed to be executed as an SSH2 subsystem and therefore only SSH2 servers support the protocol by default. It is possible in some circumstances to execute SFTP over the SSH1 protocol because SSH servers such as OpenSSH support both versions of the protocol, and while you cannot execute a subsystem using SSH1 you can execute the binary "sftp-server" directly. The Maverick.NET SFTP client attempts to find and execute the SFTP binary when it detects an SSH1 connection is in use.

Example

// Create a connection
SSHConnector con = SSHConnector.Create();
SSHClient ssh = con.Connect(new TcpClientTransport("my.domain.com, 22),
            "root", true);

// Prepare the authentication request                                
PasswordAuthentication pwd = new PasswordAuthentication();
pwd.Password = "*********";

// Authenticate the user
if(ssh.Authenticate(pwd)==AuthenticationResult.COMPLETE)
{
    // Open up a session and do something..
    SFTPClient sftp = new SFTPClient(ssh, "C:\\Documents and Settings\\lee");
    
    // Make some directories
    sftp.Mkdirs("maverick.net/sftp");

    // Change the working directory
    sftp.Cd("maverick.net/sftp");
    
    // Put a file to the remote file system
    sftp.PutFile("test.file");
    
    // Put a file using a UNC path
    sftp.PutFile("\\\\PDC\\Public\\UNC.TEST");

    sftp.Rename("test.file", "sftp-download");

    // Change the permissions on the file
    sftp.Chmod("600", "sftp-download");

    // Download the file from the remote system
    sftp.GetFile("sftp-download");

    // Remove the remote file
    sftp.Rm("sftp-download");

    // Remove the directories recursively
    sftp.Rm("maverick.net", true, true);

    // Quit and exit
    sftp.Quit():
}

ssh.Disconnect();

Requirements

Namespace: Maverick.SFTP

Assembly: Maverick.NET (in Maverick.NET.dll)

See Also

SFTPClient Members | Maverick.SFTP Namespace