Unfortunately, the Shell
class is not able to handle your case. Please try our experimental VirtualShell class, which provides such functionality.
You can use it like this:
// initialize Telnet shell
Telnet telnet = new Telnet("server");
VirtualShell shell = new VirtualShell(telnet.StartVirtualTerminal());
// set prompt
shell.Prompt = "username[@].*[$] ";
// login
shell.Expect("[Ll]ogin: ");
shell.SendCommand("username");
shell.Expect("[Pp]assword: ");
shell.SendCommand("password");
// read welcome message
Console.WriteLine("Welcome message:");
Console.WriteLine(shell.ReadAll());
// send a multipage command
Console.WriteLine("ls -la / | more:");
shell.SendCommand("ls -la / | more");
// receive the first page
Console.WriteLine("Page1:");
Console.WriteLine(shell.Expect("--More--"));
// send only the <space> to the server
shell.Terminal.SendToServer(" ");
// recieve the rest data
Console.WriteLine("Page2:");
Console.WriteLine(shell.ReadAll());
Usually you don't know how many pages you will receive. You would do something like this:
...
shell.SendCommand("ls -la / | more");
string received;
int page = 1;
int match;
do
{
// wait for Prompt or "--More--"
match = shell.Expect(out received, shell.Prompt, "--More--");
if (match < 0)
throw new InvalidOperationException(
"Neither the Prompt nor the expected regex was received within the Timeout limit.");
// display received data
Console.WriteLine("Page{0}:", page++);
Console.WriteLine(received);
// if received "--More--", send <space> to the server
if (match == 1)
shell.Terminal.SendToServer(" ");
} while (match != 0);