Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: ssh.net More Info and samples for streams

$
0
0
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);
            }

        }

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>