0

I am writing a test case where i am trying to connect to SFTP using passphrase and Private key file but getting above exception

here is my code what i have tried

public void ConnectToSFTPTest()
{
        var filename = @"C:\PvtKey.ppk";
        var pk = new PrivateKeyFile(filename, "passphrase"); --here i am getting exception
        var keyFiles = new[] { pk };

        var client =  new SftpClient("hostname", 22, "username", keyFiles);
        client.Connect();
        if(client.IsConnected)
        {
           client.Disconnect();
        }
        Assert.True(true);
}

Can anybody help me to get it working my file is ppk

shreyas35
  • 145
  • 9

1 Answers1

-1

This is because a PPK (putty private key) is a none standard format that is used by PuTTY and putty based applications, the library you're using requires an OpenSSH formatted key.

So you need to use PuTTYgen then load the PPK file and then export the file in OpenSSH format (Conversions > Export OpenSSH Key) also save the public key file this will give a converted file which one can use to fetch the data

Barkermn01
  • 6,781
  • 33
  • 83
shreyas35
  • 145
  • 9