This project is read-only.

PrivateKeyFile and Password authentication

Oct 7, 2011 at 9:53 AM

Hi,

I have to log in to an SFTP server, using both a PrivateKeyFile and a username/password authentication.

I have seen in the code that it is possible to do either, but as stated before I have to do both. Is this possible with the current implementation?

So, you can do this:

SftpClient client = new SftpClient(@"127.0.0.1", @"username", new PrivateKeyFile(@"key.ppk", @"passphrase"))

And it is also possible to do this:

SftpClient client = new SftpClient(@"127.0.0.1", @"username", @"password")

But I don't see an possibility to combine the two. Should look something like:

SftpClient client = new SftpClient(@"127.0.0.1", @"username", @"password", new PrivateKeyFile(@"key.ppk", @"passphrase"))
Am I missing something?

If it is not currently possible, is the change required to achieve this large?
I wouldn't mind exchanging code I have written to implement above feature, but it would be nice to be pointed in the right direction.

Also, I have noted the lack of proxy support, and I have added this feature (only basic proxy authentication was implemented though, not NTLM), would you be interested in receiving said code?

Thank you in advance,

Mathia Van De Poel

Oct 13, 2011 at 1:57 PM

Sorry for late response, currently busy with other project,

Well, when multiple logins are required, I thought its not up to me but up to the user to decide which method to use.

For example, I could never know should I try PrivateKey authentication first and then Password or vise versa.

 

After all, internally, what putty and other software do, is try to authenticate using one method and if it doesnt work then try another one.

The only thing I can think of I could add is to allow to provide multiple ConnectionInfo object to constructor so it could try them one after another if authentication fails.

 

Hope it helps,

 

Thanks,

Oleg