【问题标题】:SSH.NET - No suitable authentication method foundSSH.NET - 找不到合适的身份验证方法
【发布时间】:2016-04-24 20:09:56
【问题描述】:

这是我使用 SSH.NET 的代码

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

它可以在我安装在本地计算机上的 SFTP 上运行,但是当我将它指向来自客户端的真实 SFTP 服务器时,我得到了 Renci.SshNet.Common.SshAuthenticationException:找不到合适的身份验证方法来完成身份验证。

我找不到任何关于我应该使用什么身份验证方法的文档,并且在 File Zilla 上,一个简单的用户名和密码就可以解决问题。

谁能给点建议?

【问题讨论】:

    标签: c# .net ssh ftp sftp


    【解决方案1】:

    我找到了答案(至少对于我的问题,这似乎与请求的操作相同):

    我不得不将身份验证更改为KeyboardInteractiveAuthenticationMethod

    所以现在可以了:

    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 然后传递密码:

    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;
            }
        }
    }
    

    【讨论】:

    • Explanation here: "这个是我的头。原来有些服务器不支持PasswordAuthenticationMethod,所以你必须使用keyboardInteractiveAuthenticationMethod,然后处理AuthenticationPrompt事件提供密码:"
    【解决方案2】:

    好的,我的问题的答案是它不是 sftp 服务器。这是一个简单的 ftp 服务器,所以我只使用了一个 webrequest。

    首先检查服务器实际上是一个sftp服务器。

    【讨论】:

    • 这正是我所期望的,我们可以从 FileZilla 日志中轻松确定。
    猜你喜欢
    • 2023-03-15
    • 1970-01-01
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    • 2018-06-02
    • 2020-03-05
    • 2016-08-04
    • 2010-10-24
    相关资源
    最近更新 更多