No suitable authentication method found to complete authentication (publickey,keyboard-interactive).

 1 string command = Command.Text;
 2 StringBuilder result = new StringBuilder();
 3 try
 4 {
 5     var connectionInfo = new KeyboardInteractiveConnectionInfo(server, port, username);
 6 
 7     connectionInfo.AuthenticationPrompt += delegate(object sender1, AuthenticationPromptEventArgs e2)
 8     {
 9         foreach (var prompt in e2.Prompts)
10         {
11             if (prompt.Request.Equals("Password: ", StringComparison.InvariantCultureIgnoreCase))
12             {
13                 prompt.Response = password;
14             }
15         }
16     };
17 
18     using (var client = new SshClient(connectionInfo))
19     {
20         try
21         {
22             client.Connect();
23             result.Append(client.RunCommand(command).Execute() + "\r\n");
24             QAResult.Text = result.ToString();
25             client.Disconnect();
26         }
27         catch (Exception e1)
28         {
29             result.Append(e1.Message + "\r\n");
30             QAResult.Text = result.ToString();
31         }
32     }
33 }
34 catch (Exception e1)
35 {
36     result.Append(e1.Message + "\r\n");
37     QAResult.Text = result.ToString();
38 }

 

posted on 2015-10-10 11:35  Love星星  阅读(1846)  评论(0编辑  收藏  举报