'renci ssh long duration commands, with commandTimeout but not throw SshConnectionException if the remote side is off

I am using the ssh renci library. Commands can take up to 4 minutes to execute. I have to set a timeout of 4 minutes. The problem is that while the command is running if I shut down the server, the client doesn't detect that it has shut down and continues to wait the 4 minutes. How can I solve this?

The code I am using is as follows:
try
{
var command = sshClient.CreateCommand(cmdSend);
command.CommandTimeout = TimeSpan.FromSeconds(Cmd_TIMEOUT);
result = command.Execute();
}
catch (SshConnectionException e)
{
  msgException = e.Message;
  cmdResult = Constants.COMMUNICATION_ABORTED;
}
catch (Exception e)
{
    msgException = e.Message;
}
}

Thanks
ssh


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source