SSH SendReqExec — Commands with No Output
When a command is passed to SendReqExec that produces no output, such as “echo 1 > test.txt”, then do not try to read the channel (such as by calling ChannelReadAndPoll) because no data will be forthcoming and the channel read will timeout (as expected). The correct sequence of method calls would be to:
- Call SendReqExec to execute the command on the remote server.
- Call ChannelSendClose to initiate the closing of the channel.
- Call ChannelReceiveToClose to wait until the server closes the channel. In this case, no actual output data is returned because the command passed to SendReqExec produces no output. This method is called to cleanly wait for the server’s “close” message.