public static void RunExample() { try { SshConnectionInfo input = Util.GetInput(); SshShell shell = new SshShell(input.Host, input.User); if(input.Pass != null) shell.Password = input.Pass; if(input.IdentityFile != null) shell.AddIdentityFile( input.IdentityFile ); //This statement must be prior to connecting shell.RedirectToConsole(); Console.Write("Connecting..."); shell.Connect(); Console.WriteLine("OK"); while(shell.ShellOpened) { System.Threading.Thread.Sleep(500); } Console.Write("Disconnecting..."); shell.Close(); Console.WriteLine("OK"); } catch(Exception e) { Console.WriteLine(e.Message); } }
private string runStatusCommand(SshShell shell, SshExec exec, string command) { string stdout = ""; string stderr = ""; shell.Connect(); shell.RedirectToConsole(); exec.Connect(); int ret = exec.RunCommand(command, ref stdout, ref stderr); exec.Close(); shell.Close(); return stdout; }