• Loading...
ComponentPro UltimateSftp

Authenticate with a password

Language Filter: AllSend comments on this topic to ComponentPro

To authenticate a user with password-based authentication, just use this Authenticate method overload. The first parameter is the name of the user, the second one is the user's password.

using System;
using ComponentPro.Net;

...

public void DoConnect()
{
    // Create a new class instance. 
    Sftp client = new Sftp();

    client.HostKeyVerifying += HostKeyVerifying;

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

    // Or you can specify the SFTP port with 
    // client.Connect("myserver", 22); 
 
    // Authenticate. 
    client.Authenticate("userName", "password");

    // Do something here... 
    client.DownloadFile("/my remote file.dat", "my local file");

    // Disconnect. 
    client.Disconnect();
}

void HostKeyVerifying(object sender, HostKeyVerifyingEventArgs e)
{
    Console.WriteLine("Host key: " + e.HostKey);
}