Archived Forum Post

Index of archived forum posts

Question:

SSH ChannelReadAndPoll, dont wait and exit when everything was recieved ?

Mar 07 '18 at 11:14

Hi, I am having trouble tuning my application. I am trying to find best possible solution how to execute commands on device, wait for output and then disconnect. Problem is sometimes getting output takes about 15-20 seconds, therefore I used also ChannelReadAndPoll command. But I see that when I set up this command to have timeout 30 seconds, It waits also around 30 seconds when it already gets all the output which is time wasting.

How can I tune the application, so when it gets all the output or a specific line faster It can disconnect.

/*THIS IS THE SET OF COMMANDS I WANT TO RUN */

              success = end_device.ChannelSendString(channelNum, command, "ansi");

              if (success != true)
              {
                    result = "Execution of commands failed";
                    return Tuple.Create(false, result);
              }

              // Wait and fetch streaming output from Device
              var cmdOutput = end_device.ChannelReadAndPoll(channelNum, 30000);
              if (cmdOutput < 0)
              {
                    result = end_device.LastErrorText;
                    return Tuple.Create(false, result);
              }

              /* SEND END OF COMMANDS */
              success = end_device.ChannelSendEof(channelNum);
              if (success != true)
              {
                    result = "Execution of commands failed";
                    return Tuple.Create(false, result);
              }

              //  After recieving output close the channel:
              success = end_device.ChannelSendClose(channelNum);
              if (success != true)
              {
                    result = end_device.LastErrorText;
                    return Tuple.Create(false, result);
              }

              if (success)
              {
                    result += end_device.GetReceivedText(channelNum, "ansi");
                    return Tuple.Create(true, result);
              }