无法使用SSH.NET库连接到AIX(Unix)框 - 错误:值不能为空

Bla*_*sor 8 .net c# ssh aix putty

我正在尝试连接到AIX盒并使用SSH.NET库执行一些命令.以下是代码snipplet

KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(username);
PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(username, password);

ConnectionInfo connectionInfo = new(ConnectionInfo(servername, 22, username, pauth,kauth);
SshClient sshClient = new SshClient(connectionInfo);
sshClient.Connect();
SshCommand sshCommand = sshClient.RunCommand("mpstat");
Console.WriteLine(sshCommand.Result);
Console.ReadKey();
Run Code Online (Sandbox Code Playgroud)

当我尝试在线路连接时,我收到以下异常消息sshClient.Connect()

{"值不能为空.\ r \n参数名称:数据"}

堆栈跟踪是

   at Renci.SshNet.KeyboardInteractiveAuthenticationMethod.Authenticate(Session session)
   at Renci.SshNet.ConnectionInfo.Authenticate(Session session)
   at Renci.SshNet.Session.Connect()
   at Renci.SshNet.BaseClient.Connect()
Run Code Online (Sandbox Code Playgroud)

我相信我传递的凭据是有效的,因为我能够使用PuTTY具有相同凭据的客户端登录.有任何想法吗?

Bla*_*sor 15

经过一些研究,我找到了解决方案.希望它能帮助别人.

该键盘交互认证应使用AuthenticationPrompt事件应具有以下功能覆盖

void HandleKeyEvent(Object sender, AuthenticationPromptEventArgs e)
{
    foreach (AuthenticationPrompt prompt in e.Prompts)
    {
        if (prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) != -1)
        {
            prompt.Response = password;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

函数调用代码:

KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(username);
PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(username, password);

kauth.AuthenticationPrompt += new EventHandler<AuthenticationPromptEventArgs>(HandleKeyEvent);

ConnectionInfo connectionInfo = new ConnectionInfo(serverName, port, username, pauth, kauth);

sshClient = new SshClient(connectionInfo);
sshClient.Connect();
Run Code Online (Sandbox Code Playgroud)