Hi everyone,
I'm using Renci SSH within my vb.net project and wondering how I can pass multiple commands and keep the session open.
I'm just testing things at the moment, but I'd like to navigate to a directory "cd /home/temp/" with one command, then after that has run, do something like "ls -l" and provide the results in a label or text box.
My code at present is as follows...
I'm using Renci SSH within my vb.net project and wondering how I can pass multiple commands and keep the session open.
I'm just testing things at the moment, but I'd like to navigate to a directory "cd /home/temp/" with one command, then after that has run, do something like "ls -l" and provide the results in a label or text box.
My code at present is as follows...
Private Sub btnSSHTest_Click(sender As Object, e As EventArgs) Handles btnSSHTest.Click
'Create the objects needed to make the connection'
Dim connInfo As New Renci.SshNet.PasswordConnectionInfo(txtConnectionNode.Text, txtboxUsername.Text, txtboxPassword.Text)
Using client As New Renci.SshNet.SshClient(connInfo)
client.Connect()
Dim cmd As Renci.SshNet.SshCommand
Dim result As String
Dim result2 As String
cmd = client.CreateCommand("cd /home/temp/")
result = cmd.Execute
cmd = client.CreateCommand("ls -l")
cmd.CommandTimeout = TimeSpan.FromSeconds(10)
result = cmd.Execute
result2 = cmd.Error
TextBox1.Text = cmd.ExitStatus
If String.IsNullOrEmpty(result2) Then
TextBox1.Text = result2
End If
TextBox1.Text = result
client.Disconnect()
End Using
End Sub
But the ls -l command just doesn't recognise that the cd /home/temp/ command has been run. Am I missing something? Does the SSH not work this way?