Discuss this help topic in SecureBlackbox Forum

SSH: Implement Command channel in the SSH server

Command channels, while being a separate class of entities as per the SSH standard, are very similar in their nature to shell channels from the SSH server implementer's viewpoint. Just like with a shell, executing a command involves creation of a local (to the server) process and redirecting its STDIN, STDOUT and STDERR channels over the connection. You can even emulate the shell channel over the command channel by invoking the shell 'manually' (by running a 'cmd' command).

Therefore most of the instructions given for shell channels are also appropriate for the command channels. The only differences are the following:

  1. Instead of handling OnBeforeOpenShell and OnOpenShell events you handle OnBeforeOpenCommand and OnOpenCommand. You can handle both sets to support shell and commands independently in your server.
  2. The built in TElShellSSHSubsystemHandler component does support command channels - in this case you are expected to assign the command to its Command property.


private void m_SSHServer_OnOpenCommand(object Sender, TElSSHTunnelConnection Connection, string Command)
	TElSSHSubsystemThread thread = new TElSSHSubsystemThread(new TElShellSSHSubsystemHandler(Connection, true), Connection, true);
	((TElShellSSHSubsystemHandler)(thread.Handler)).Command = Command;
	thread.Handler.OnUnsafeOperationStart += new TNotifyEvent(Handler_OnUnsafeOperationStart);
	thread.Handler.OnUnsafeOperationEnd += new TNotifyEvent(Handler_OnUnsafeOperationEnd);

You are always free to implement your own command handler for advanced scenarios not covered by TElShellSSHSubsystemHandler.

How To articles about SSH server

Discuss this help topic in SecureBlackbox Forum