private static void Main(string[] args) { Console.WindowWidth = 100; Console.WindowHeight = 50; SSHControl ssh = new SSHControl(); //ssh.Start(); SSHJob job = new SSHJob(); job.Commands = new List<string>(); Console.WriteLine("Enter IP:"); job.IP = Console.ReadLine(); Console.WriteLine("Enter Username:"******"Enter PW:"); job.PW = Console.ReadLine(); while (true) { Console.WriteLine("Enter command:"); string cmd = Console.ReadLine(); job.Commands.Add(cmd); ssh.ExecSSHJob(job); job.Commands.Remove(cmd); } //ssh.Stop(); }
public void ExecSSHJob(SSHJob job) { TheLog.Info($"Connecting to {job.IP} as {job.User}"); try { using (var client = new SshClient(job.IP, job.User, job.PW)) { client.Connect(); foreach (var cmd in job.Commands) { TheLog.Info($"Running: [{cmd}]"); var result = client.RunCommand(cmd); TheLog.Info($"Error: {result.Error}"); TheLog.Info($"Response: {result.Result}"); } client.Disconnect(); TheLog.Info($"Disconnecting from {job.IP}"); } } catch (Exception ex) { TheLog.Error($"Encountered an error! Removing current job from queue"); string logmsg = string.Join(",\n", job.Commands); TheLog.Error($"job::ip[{job.IP}] user[{job.User}] commands[{logmsg}]"); TheLog.Error($"{ex.Source}"); TheLog.Error(ex); //QueuedCommands?.Remove(job); } }