Dart.Ssh Namespace > SshConnection Class : Challenge Event |
'Declaration Public Event Challenge As SshConnection.ChallengeEventHandler
'Usage Dim instance As SshConnection Dim handler As SshConnection.ChallengeEventHandler AddHandler instance.Challenge, handler
public event SshConnection.ChallengeEventHandler Challenge
public: __event SshConnection.ChallengeEventHandler* Challenge
public: event SshConnection.ChallengeEventHandler^ Challenge
The event handler receives an argument of type ChallengeEventArgs containing data related to this event. The following ChallengeEventArgs properties provide information specific to this event.
Property | Description |
---|---|
Echo | Gets information sent by the server that indicates whether responses will be echoed back to the client. |
Instruction | Gets the instruction string sent by the server. |
Name | Gets the name string sent by the server. |
Prompt | Gets the prompt or prompts sent by the server. |
Response | Gets a string array that the user should initialize to values that will be sent to the server for authentication. Each Response correlates to a Prompt at the same index. |
For each ChallengeEventArgs.Prompt, populate a ChallengeEventArgs.Response at the same index to proceed with authentication.
See the ComponentBase.SynchronizingObject property for important information on updating UI controls from within this event.
private void button1_Click(object sender, System.EventArgs e) { //Connect to the server ssh1.Connection.RemoteEndPoint.HostNameOrAddress = myServerHostname; ssh1.Connection.RemoteEndPoint.Port = myServerPort; //Usually 22 ssh1.Connect(); ssh1.Authenticate(myUsername, new string[] { }); } private void ssh1_Challenge(object sender, ChallengeEventArgs e) { for (int i = 0; i <= e.Prompt.Length - 1; i++) { if (e.Prompt[i] == "password:") e.Response[i] = myPassword; //If the server presents additional challenges, populate each response here } }
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click 'Connect to the server ssh1.Connection.RemoteEndPoint.HostNameOrAddress = myServerHostname ssh1.Connection.RemoteEndPoint.Port = myServerPort 'Usually 22 ssh1.Connect() ssh1.Authenticate(myUsername, New String() { }) End Sub Private Sub ssh1_Challenge(ByVal sender As Object, ByVal e As ChallengeEventArgs) Handles ssh1.Challenge For i As Integer = 0 To e.Prompt.Length - 1 If e.Prompt(i) = "password:" Then e.Response(i) = myPassword End If 'If the server presents additional challenges, populate each response here Next i End Sub