Here is what I have that works
client.Connect();
using (ShellStream shellStream = client.CreateShellStream("dumb", 80, 24, 800, 600, 1024))
{
var reader = new StreamReader(shellStream);
var writer = new StreamWriter(shellStream);
writer.AutoFlush = true;
while (shellStream.Length == 0)
{
Thread.Sleep(500);
}
Regex userPromptMatch = new Regex(@"#");
string prompt = shellStream.Expect(userPromptMatch, new TimeSpan(0, 1, 0));
WriteStream("term length 0", writer, shellStream);
Console.WriteLine(prompt);
string result = shellStream.Expect("term length 0", new TimeSpan(0, 1, 0));
Console.WriteLine(result);
WriteStream("show int desc", writer, shellStream);
result = shellStream.Expect("show int desc", new TimeSpan(0, 1, 0));
Console.WriteLine(result);
string final = shellStream.Expect(prompt, new TimeSpan(0, 1, 0));
Console.WriteLine(final);
using (writer = File.AppendText(@"C:\Users\test.txt"))
{
writer.WriteLine(final);
}
}
client.Disconnect();
}
private static void WriteStream(string cmd, StreamWriter writer, ShellStream stream)
{
writer.WriteLine(cmd);
while (stream.DataAvailable == false)
{
Thread.Sleep(1000);
}
}