This is my code using SSH.NET
using (var sftp = new SftpClient(host, username, password))
{
sftp.Connect();
}
It works on
I found the answer (at least for my problem, which seems to be the same as the op requested):
I had to change the Authentication to KeyboardInteractiveAuthenticationMethod
So this works now:
KeyboardInteractiveAuthenticationMethod keybAuth = new KeyboardInteractiveAuthenticationMethod(SFTP_USR);
keybAuth.AuthenticationPrompt += new EventHandler(HandleKeyEvent);
ConnectionInfo conInfo = new ConnectionInfo(SFTP_HST, SFTP_PRT, SFTP_USR, keybAuth);
using (SftpClient sftp = new SftpClient(conInfo))
{
sftp.Connect();
// Do SFTP Stuff, Upload, Download,...
sftp.Disconnect();
}
HandleKeyEvent
then passes the Password:
private void HandleKeyEvent(object sender, AuthenticationPromptEventArgs e)
{
foreach (AuthenticationPrompt prompt in e.Prompts)
{
if (prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) != -1)
{
prompt.Response = SFTP_PWD;
}
}
}