• Loading...
ComponentPro UltimateSftp

Authenticate with a key

Language Filter: AllSend comments on this topic to ComponentPro

It is more desirable to use public key cryptography rather than using a password to authenticate. The SSH server keeps a database of public keys for each account - exact details of this depends on the server (OpenSSH keeps the public keys in ~/.ssh/authorized_keys file in each account's home directory). A public key has a corresponding private key that is kept secret by the client. To authenticate to the server using public key cryptography, you need this private key. To authenticate using your private key, simply call the Authenticate method with the SecureShellPrivateKey object created from the provided name of the private key and its passphrase. If you find out that your private key format is not supported by our component, please do not hesitate to send a request to us at support@componentpro.com.

using ComponentPro.Net;


// Create a new class instance.
Sftp client = new Sftp();

// Connect to the SFTP server.
client.Connect("myserver", 22);

// Authenticate user with a private key.
client.Authenticate("userName", "c:\\privateKey.key", "pkeypassword");

// It's possible to use both username/password and private key to authenticate. 
// client.Authenticate("userName", "password", "c:\\privateKey.key", "pkeypassword"); 
// Do something here...
client.DownloadFile("/my remote file.dat", "my local file");

// Disconnect.