static void pr_WriteLine(object sender, ProgramRunner.ProgramEventArgs e) { if (e.Message.IndexOf("Store key in cache? (y/n)") >= 0) { pr.SendCommand("y"); } }
private static bool RunPscp(string passwd, string args) { string dir = Path.GetDirectoryName(Application.ExecutablePath); var exe = Path.Combine(dir, "pscp.exe"); if (!File.Exists(exe)) { exe = "pscp.exe"; } if (!File.Exists(exe)) { throw new FileNotFoundException(exe); } pr = new ProgramRunner(); pr.Run(exe, args); pr.SendCommand("y"); int exitCode = pr.WaitForExit(); var output = pr.Output; foreach (var item in pr.Output) { Logger.WriteLine(item); } if (exitCode != 0) { throw new IOException("Error copying with PSCP " + args.Replace(passwd, "xxxxx")); } return(exitCode == 0); // var output = ProgramRunner.RunExecutable(exe, args); //TextFile tf = new TextFile(output); //if (tf.IndexOf("The server's host key is not cached in the registry.") >= 0) //{ // // try again. // pr = new ProgramRunner(); // // pr.WriteLine += new ProgramRunner.InfoEventHandler(pr_WriteLine); // pr.Run("pscp", args.Replace("-batch","")); // pr.SendCommand("y"); // exitCode = pr.WaitForExit(); // // tf = new TextFile(pr.Output); //} }