hi vaccaridaniele,
why do you use this regular expressions? Look at my code at the end of this posting. It is just an adapted copy of yours. ;) But it runs endless the while loop.
why do you use this regular expressions? Look at my code at the end of this posting. It is just an adapted copy of yours. ;) But it runs endless the while loop.
var connectionInfo = new ConnectionInfo("server", 22, "user",
new PrivateKeyAuthenticationMethod("user",
new PrivateKeyFile(File.OpenRead(@"C:\Path\to\file\file.key"), "")));
using (var client = new Renci.SshNet.SshClient(connectionInfo))
{
try
{
client.Connect();
ShellStream shells = client.CreateShellStream("test", 80, 24, 800, 600, 1024);
Regex regex = new Regex(@"\[.*@.*\][\$|\#]");
shells.WriteLine("su");
String outp = "";
var match = regex.Match(outp);
while ((shells.DataAvailable || !match.Success || outp == ""))
{
outp += shells.Read();
Console.WriteLine(outp);
match = regex.Match(outp);
Console.WriteLine(shells.DataAvailable);
Console.WriteLine(match.Success);
}
shells.WriteLine("password");
outp = "";
match = regex.Match(outp);
while (shells.DataAvailable || !match.Success || outp == "")
{
outp += shells.Read();
Console.WriteLine(outp);
match = regex.Match(outp);
}
client.Disconnect();
}
catch (SshAuthenticationException ex)
{
Console.WriteLine(ex.Message);
}