Archived Forum Post

Index of archived forum posts

Question:

Difference between SSH SendReqExec and SendReqShell

Apr 24 '15 at 08:59

What is the difference between SendReqExec and SendReqShell? Both send commands to be executed remotely..


Answer

The SendReqExec command is equivalent to doing an "rexec" (http://linux.die.net/man/1/rexec).

It's not the same as establishing a remote shell as in this example: http://www.example-code.com/vcpp/ssh_remote_command.asp

A remote shell SSH session is where a remote shell is established. The output received back to the SSH client includes the command prompt. Commands are sent one after the other just as they are typed, with a "n" or "rn" terminating the command, and the command output is received back along with the next command prompt. It's the equivalent of a shell session where the SSH client (your app) is the human at the keyboard. (see the detailed answer to this Chilkat forum post: http://www.chilkatforum.com/questions/1272/how-to-get-the-full-output-of-an-ssh-command )

A remote command is entirely different. It's a single command sent without "n" or "rn" because it's not the equivalent of being the human at the keyboard. You send the command, such as "ls", and get the response, which does not include the shell prompt. You can only do a single rexec (i.e. SendReqExec) in a session channel. To execute the next rexec, you would close the session channel, open a new one, and issue the next rexec. There is no "state". It wouldn't makes sense to "cd" to a directory in one rexec, and then do another rexec assuming you are now in that directory. A "cd" only makes sense if you are in a remote shell. If the rexec command produces no output, such as a "cd" command would output nothing, then there is no output to receive. It still executed the command remotely, but for no reason.