91
SSH / Re: SSH ChannelReadAndPoll, dont wait and exit when everything was recieved ?
« Last post by marhyno on March 08, 2018, 07:46:43 AM »Unfortunately this doesnt work, I wont even fetch any output from the device. I commented out the ChannelReadAndPoll and added ChannelReceiveToClose. But this time I dont get any output.
/*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);
}
// After recieving output close the channel:
success = end_device.ChannelReceiveToClose(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);
}
/*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);
}
// After recieving output close the channel:
success = end_device.ChannelReceiveToClose(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);
}