ssh.net No suitable authentication
ConnectionInfo pci;
try
{
pci = new PasswordConnectionInfo(host, port, username, password);
}
catch (Exception ex)
{
if (ex.ToString().Contains("No suitable authentication"))
{
KeyboardInteractiveAuthenticationMethod keybAuth = new KeyboardInteractiveAuthenticationMethod(username);
keybAuth.AuthenticationPrompt += new EventHandler<AuthenticationPromptEventArgs>((sender, e) => {
foreach (AuthenticationPrompt prompt in e.Prompts)
{
if (prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) != -1)
{
prompt.Response = password;
}
}
});
pci = new ConnectionInfo(host, port, username, keybAuth);
}
else
{
throw ex;
}
}
using(var client = new SshClient(pci))
{
}