Authentication with PPK key in SSH.NET

SSH.NET does not support .ppk key files. You have to use PuTTYgen to convert the .ppk key to OpenSSH format.

See How to convert SSH keypairs generated using PuTTYgen (Windows) into key-pairs used by ssh-agent and Keychain (Linux).


Original answer, before the question was edited:

You are using multifactor private key and keyboard interactive authentication in FileZilla:

2017-04-03 16:25:26 8120 3 Trace: Offered public key from “Z:\SFTP SETUP\CJ22_PVT.ppk”
2017-04-03 16:25:26 8120 3 Trace: Offer of public key accepted, trying to authenticate using it.
2017-04-03 16:25:29 8120 3 Trace: Further authentication required
2017-04-03 16:25:30 8120 3 Trace: Using keyboard-interactive authentication. inst_len: 0, num_prompts: 1
2017-04-03 16:25:30 8120 3 Command: Pass: *********
2017-04-03 16:25:30 8120 3 Trace: Access granted

While, you are using simple password authentication in your code:

using (var sftp = new SftpClient(Host, Port, Username, Password))

How can you even expect this to work?


To implement multifactor authentication, you have to use ConnectionInfo.

var keybInterMethod = new KeyboardInteractiveAuthenticationMethod(username);
keybInterMethod.AuthenticationPrompt +=
    (sender, e) => { e.Prompts.First().Response = password; };

AuthenticationMethod[] methods = new AuthenticationMethod[] {
    new PrivateKeyAuthenticationMethod(username, new PrivateKeyFile(privateKey)),
    keybInterMethod
};
ConnectionInfo connectionInfo = new ConnectionInfo(hostname, username, methods);

using (var sftp = new SftpClient(connectionInfo))
{
    sftp.Connect();

    // ...
}

Leave a Comment