How to execute a rise series of commands through a ssh command?

Jan 11, 2011 at 7:14 AM
Edited Jan 11, 2011 at 10:51 AM


        Using client As New SshClient(host, user, password)


            ' Execute first pwd
            Dim cmd As SshCommand = client.CreateCommand("pwd", System.Text.Encoding.UTF8)

            ' Change dir via cd
            cmd.Execute("cd Desktop")

            ' Execute second pwd command


        End Using


In the above example the change directory command has no effect. The result of pwd is the same path. I have read in another discussion it's because every executed command uses a new channel.

How can I execute a rise series of commands through the same channel and an own exit status and result for each command?

Jan 11, 2011 at 3:04 PM

Based on the protocol definition it says:  "When the command running at the other end terminates, the following message can be sent to return the exit status of the command. Returning the status is RECOMMENDED."

So I think that this scenario cannot be supported.

What you can do is to execute everything as one command and chain them "cd Desktop;pwd" will give you desired result, you just wont be able to collect exit status from the first command execution, unless you add "echo $?" and capture results.


Hope it helps.