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); }
static private bool UnzipImageOnTarget() { string target_filename = PuttyConstants.GetTargetImageFilename(); UtilsPutty.CopyFileToTarget(PuttyConstants.GetUser(), PuttyConstants.GetPassword(), PuttyConstants.GetIP(), target_filename, "/tmp/image_to_unzip.zip"); string unzip_script = String.Join( "\n", "#!/bin/sh", "cd /tmp", "tar xvf image_to_unzip.zip", "exit 123"); string stdout, stderr; PuttyCommand command = new PuttyCommand(); int return_code = command.RunScriptToCompletion(PuttyConstants.GetUser(), PuttyConstants.GetPassword(), PuttyConstants.GetIP(), unzip_script, out stdout, out stderr); return(return_code == 123); }
public bool Start(string user, string pw, string ip_addr) { _process = UtilsPutty.StartPuttyShell(user, pw, ip_addr); return(true); }