public int RunScriptToCompletion(string user, string pw, string ip_addr, string script, out string stdout, out string stderr) { // 0. Remove any DOS line endings script = script.Replace("\r\n", "\n"); // 1. Store script in a local file string local_temp_file = System.IO.Path.GetTempFileName(); using (var file = new StreamWriter(local_temp_file)) { file.Write(script); } // 2. copy this local file to a remote file string remote_filename = "/tmp/target_helper.sh"; // todo: replace this with something that wontt collide bool copy_result = UtilsPutty.CopyFileToTarget(user, pw, ip_addr, local_temp_file, remote_filename); int result; if (copy_result) { // 3. execute the remote file result = UtilsPutty.ShellExecuteToCompletion(user, pw, ip_addr, remote_filename, out stdout, out stderr); } else { result = -1; // seans putty rule: -1 is error from putty stdout = ""; stderr = ""; } return(result); }
public bool Start(string user, string pw, string ip_addr) { _process = UtilsPutty.StartPuttyShell(user, pw, ip_addr); return(true); }