Interactive.aml 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <topic id="281ac0c3-0d6c-4bf2-ae64-db6862d6fff5" revisionNumber="1">
  3. <developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
  4. <introduction>
  5. <para>
  6. This section will describe how to establish connection using interactive authentication method.
  7. </para>
  8. <list class="bullet">
  9. <listItem>
  10. <para>
  11. <link xlink:href="#UseKeyboardInteractiveConnectionInfoSection">Use KeyboardInteractiveConnectionInfo to connect.</link>
  12. </para>
  13. </listItem>
  14. </list>
  15. </introduction>
  16. <section address="UseKeyboardInteractiveConnectionInfoSection">
  17. <title>Use KeyboardInteractiveConnectionInfo to connect</title>
  18. <content>
  19. <para>
  20. Some server support only interactive method of authentication, even if they still use username and password.
  21. For this scenario you must use <codeEntityReference>T:Renci.SshNet.KeyboardInteractiveConnectionInfo</codeEntityReference> object.
  22. For this case you need to handle <codeEntityReference>E:Renci.SshNet.KeyboardInteractiveConnectionInfo.AuthenticationPrompt</codeEntityReference> event.
  23. This event can be raised more then once if server needs to. For example, first time to ask you for yousername and second for the password but there could be other scenarious where more questions will need to be answered for authentication to complete.
  24. </para>
  25. <code language="cs" title="Use username and password to connect example">
  26. <![CDATA[
  27. var connectionInfo = new KeyboardInteractiveConnectionInfo("host", "username");
  28. connectionInfo.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e)
  29. {
  30. Console.WriteLine(e.Instruction);
  31. foreach (var prompt in e.Prompts)
  32. {
  33. Console.WriteLine(prompt.Request);
  34. prompt.Response = Console.ReadLine();
  35. }
  36. };
  37. using (var client = new SshClient(connectionInfo))
  38. {
  39. client.Connect();
  40. ...
  41. client.Disconnect();
  42. }
  43. ]]>
  44. </code>
  45. </content>
  46. </section>
  47. <relatedTopics>
  48. <codeEntityReference>T:Renci.SshNet.KeyboardInteractiveConnectionInfo</codeEntityReference>
  49. <codeEntityReference>T:Renci.SshNet.SshClient</codeEntityReference>
  50. <codeEntityReference>M:Renci.SshNet.SshBaseClient.Connect()</codeEntityReference>
  51. </relatedTopics>
  52. </developerConceptualDocument>
  53. </topic>