thanks for all reply
i have done the work.
here is my code.
i have done the work.
here is my code.
string input = String.Empty;
string output = String.Empty;
bool isFirst = true;
private void SSHConnect()
{
client = new SshClient("172.19.118.141", "trade", "trade");
client.ConnectionInfo.Encoding = ASCIIEncoding.Default;
client.Connect();
ShellStream shells = client.CreateShellStream("test", 80, 24, 800, 600, 1024);
input = "ping 127.0.0.1 -c 5";
shells.DataReceived += new EventHandler<Renci.SshNet.Common.ShellDataEventArgs>(shells_DataReceived);
shells.Expect(new Regex(@"\$ $"));
shells.WriteLine(input);
shells.Expect(new Regex(@"\$ $"));
client.Disconnect();
}
void shells_DataReceived(object sender, Renci.SshNet.Common.ShellDataEventArgs e)
{
string newline = (client.ConnectionInfo.Encoding.GetString(e.Data));
if (newline.Contains('\n'))
{
Regex regex = new Regex(@"\[.*@.*\][\$|\#]");
string[] str = newline.Split('\n');
for (int i = 0; i < str.Length; i++)
{
output += str[i];
var match = regex.Match(output);
if (output.StartsWith("Last login") || match.Success || output == String.Empty)
{ output = String.Empty; continue; }
if (isFirst && output == input)
{ output = String.Empty; isFirst = false; continue; }
Console.WriteLine(output);
output = String.Empty;
}
}
else
output += newline;
}