SSH.NET - No suitable authentication method found

前端 未结 2 956
无人及你
无人及你 2021-02-19 06:56

This is my code using SSH.NET

using (var sftp = new SftpClient(host, username, password))
{                
    sftp.Connect();  
}

It works on

相关标签:
2条回答
  • 2021-02-19 07:25

    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<AuthenticationPromptEventArgs>(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;
            }
        }
    }
    
    0 讨论(0)
  • 2021-02-19 07:40

    Ok so the answer to my problem is that it wasn't an sftp server. It was a simple ftp server so i just used a webrequest.

    Check the server is actually an sftp server first.

    0 讨论(0)
提交回复
热议问题