Exemplo n.º 1
0
        static private Process StartPuttyShell(string arguments)
        {
            Process process = new Process();

            process.StartInfo.FileName  = PuttyConstants.GetPUTTYFilename();
            process.StartInfo.Arguments = arguments;
            process.Start();
            return(process);
        }
Exemplo n.º 2
0
        static public bool CopyDirectoryFromTarget(string user, string pw, string ip_addr, string src_filename, string dest_filename)
        {
            string arguments = String.Format("-r -l {0} -pw {1} {2}:{3} {4}",
                                             user,         // 0
                                             pw,           // 1
                                             ip_addr,      // 2
                                             src_filename, // 3
                                             dest_filename);
            string outstring, errstring;

            return(ExecuteToCompletion(PuttyConstants.GetPSCPFilename(), arguments, out outstring, out errstring) == 0);
        }
Exemplo n.º 3
0
        static public bool CopyFileToTarget(string user, string pw, string ip_addr, string src_filename, string dest_filename)
        {
            string arguments = String.Format("-l {0} -pw {1} {2} {3}:{4}",
                                             user,
                                             pw,
                                             src_filename,
                                             ip_addr,
                                             dest_filename);
            string outstring, errstring;

            return(ExecuteToCompletion(PuttyConstants.GetPSCPFilename(), arguments, out outstring, out errstring) == 0);
        }
Exemplo n.º 4
0
        static private bool RunInstallScript()
        {
            string run_install_script = String.Join(
                "\n",
                "#!/bin/sh",
                "cd /tmp",
                "source ./install_debs_helper.sh " + PuttyConstants.GetPassword(),
                "exit 123");

            string       stdout, stderr;
            PuttyCommand command     = new PuttyCommand();
            int          return_code = command.RunScriptToCompletion(PuttyConstants.GetUser(), PuttyConstants.GetPassword(), PuttyConstants.GetIP(),
                                                                     run_install_script, out stdout, out stderr);

            return(return_code == 123);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        static public int ShellExecuteToCompletion(string user, string pw, string ip_addr, string remote_filename,
                                                   out string stdout, out string stderr)
        {
            // Algorithm create a 'putty command script'
            // create a command file, stuff the command to execute in there, then execute it
            string local_temp_file = System.IO.Path.GetTempFileName();

            using (var file = new StreamWriter(local_temp_file))
            {
                file.Write("bash -e " + remote_filename + "\n");
            }

            string arguments = String.Format("-ssh {0}@{1} -pw {2} -m {3} -batch",
                                             user,
                                             ip_addr,
                                             pw,
                                             local_temp_file);

            int result = ExecuteToCompletion(PuttyConstants.GetPLINKFilename(), arguments, out stdout, out stderr);

            System.IO.File.Delete(local_temp_file);

            return(result);
        }