All wodCrypt (12) wodSSH (10) wodSFTP (23) wodSSHServer (1) wodSSHTunnel (11) wodSSHpackage wodSFTPdll wodSSH.NET (10) wodSFTP.NET (24) wodFtpDLX.NET (22) wodWebServer.NET (10) wodAppUpdate (13) wodHttpDLX (8) wodFtpDLX (22) wodTelnetDLX wodFTPServer (3) wodWebServer (10) wodVPN wodXMPP (13) | All ** [Visual Basic] ** [C#] ** [VB.NET] ** Send multiple commands to SSH server using asynchronous connection
VB code
Dim WithEvents wodSSH1 As wodSSHCom Dim i As Integer Private Sub Form_Load() Set wodSSH1 = New wodSSHCom i = 1 'Authenticate with server using hostname, login, password. wodSSH1.HostName = "your_hostname" wodSSH1.Login = "your_login" wodSSH1.Password = "your_password" 'Regular expression is used for a prompt. wodSSH1.Prompt = "regex:[\$%#>] $" wodSSH1.Connect End Sub 'PromptReceived event fires when the command prompt string is received. Private Sub wodSSH1_PromptReceived() If i = 1 Then wodSSH1.Send "command 1" + vbLf ElseIf i = 2 Then wodSSH1.Send "command 2" + vbLf ElseIf i = 3 Then wodSSH1.Send "command 3" + vbLf End If 'Receive command output. Debug.Print wodSSH1.Receive i = i + 1 End Sub VB.NET code
Uses wodSSH.NET component
Dim WithEvents wodSSH1 As WeOnlyDo.Client.SSH Dim i As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load wodSSH1 = New WeOnlyDo.Client.SSH i = 1 'Authenticate with server using hostname, login, password. wodSSH1.Hostname = "your_hostname" wodSSH1.Login = "your_login" wodSSH1.Password = "your_password" 'Regular expression is used for a prompt. wodSSH1.Prompt = "regex:[\$%#>] $" wodSSH1.Connect() End Sub 'PromptReceived event fires when the command prompt string is received. Private Sub wodSSH1_PromptReceivedEvent(ByVal Sender As Object, ByVal Args As System.EventArgs) Handles wodSSH1.PromptReceivedEvent If i = 1 Then wodSSH1.Send("command 1" + vbLf) ElseIf i = 2 Then wodSSH1.Send("command 2" + vbLf) ElseIf i = 3 Then wodSSH1.Send("command 3" + vbLf) End If 'Receive command output. Console.WriteLine(wodSSH1.Receive) i = i + 1 End Sub C# code
Uses wodSSH.NET component
WeOnlyDo.Client.SSH wodSSH1; short i; private void Form1_Load(object sender, EventArgs e) { wodSSH1 = new WeOnlyDo.Client.SSH(); wodSSH1.PromptReceivedEvent +=new WeOnlyDo.Client.SSH.PromptReceivedDelegate(wodSSH1_PromptReceivedEvent); i = 1; //Authenticate with server using hostname, login, password. wodSSH1.Hostname = "your_hostname"; wodSSH1.Login = "your_login"; wodSSH1.Password = "your.password"; //Regular expression is used for a prompt. wodSSH1.Prompt = "regex:[\\$%#>] $"; wodSSH1.Connect(); } //PromptReceived event fires when the command prompt string is received. void wodSSH1_PromptReceivedEvent(object Sender, EventArgs Args) { if (i == 1) { wodSSH1.Send("command 1\n"); } else if (i == 2) { wodSSH1.Send("command 2\n"); } else if (i == 3) { wodSSH1.Send("command 3\n"); } //Receive command output. Console.WriteLine(wodSSH1.Receive()); i++; } |