SSH Code Example: Keyboard Interactive authentication

Shows how to perform keyboard interactive authentication.

Date Entered: 09/17/2008    Last Updated: 09/17/2008

In Version 8 of the toolkit we have introduced support for Keyboard Interactive authentication. To use this type of authentication you'll need to set the SSHAuthMode property to amKeyboardInteractive and make use of the new SSHKeyboardInteractive event. For instance:

C#
sftp.SSHAuthMode = SftpSSHAuthModes.amKeyboardInteractive;
sftp.SSHUser = "test";
sftp.SSHLogon("server", 22);
//No password is specified here because it will be supplied 
//within the event in response to a prompt.

...
void sftp_OnSSHKeyboardInteractive
  (object sender, SftpSSHKeyboardInteractiveEventArgs e)
{
	if (e.Prompt.ToLower().Contains("password"))
		e.Response = "my_password";
}

The Response field should be assigned with the value that you want to respond to the prompt with. In the case where the Prompt field is an empty string you may check the Instructions field to obtain informational messages sent by the server.

The help file contains more detail about the individual fields of the event parameter.


We appreciate your feedback.  If you have any questions, comments, or suggestions about this entry please contact our support team at kb@nsoftware.com.