Beispiel #1
0
        private void btnStartPointsat_Click(object sender, EventArgs e)
        {
            ssh = new SshStream(txtIP.Text, txtUsername.Text, txtPassword.Text);
            ssh.Write("cd svs");

            ReadSSH();
            ssh.Write("export LD_LIBRARY_PATH=/svs/libs");

            ReadSSH();

            ssh.Write("./pointsat_core&");
            ReadSSH();
        }
Beispiel #2
0
        public static string EjecutarSSH(string pServidor, string pUsuario, string pPassword, string pComando)
        {
            SshStream SSH = null;

            try
            {
                // instancia del objeto SSHShell
                SSH = new SshStream(pServidor, pUsuario, pPassword);
                // ejecutar el comando
                SSH.Write(pComando);

                string ret = SSH.ReadResponse();
                // confirmar
                SSH.Flush();

                return(ret);
            }
            catch (Exception ex)
            { throw ex; }
            finally
            {
                //cerrar conexion SSH
                SSH.Close();
            } // end try
        }     // end EjecutarSHH
Beispiel #3
0
 public static void MakeNewDirectory(string dirName)
 {
     //create a new ssh stream
     using (SshStream ssh = new SshStream(MACHINE_IP, USER_NAME, PASSWORD))
     {
         //writing to the ssh channel
         ssh.Write("mkdir " + dirName);
     }
 }
Beispiel #4
0
 public void ssh_command(string type, string host, string user, string password, string command)
 {
     if (type == "list dir")
     {
         Sftp sftp = new Sftp(host, user, password);
         try
         {
             sftp.Connect();
             ArrayList analyses = sftp.GetFileList(command);
             if (analyses.Count > 0)
             {
                 foreach (string run in analyses)
                 {
                     if (run.Length > 10)
                     {
                         this.stdRunsList.Items.Add(run);
                     }
                 }
                 count_label.Text = "Count: " + stdRunsList.Items.Count.ToString();
                 connected();
             }
         }
         catch
         {
             ConnectionError.Visible = true;
             pwdBox.ResetText();
         }
         finally
         {
             sftp.Close();
         }
     }
     else if (type == "kill")
     {
         ssh.Write(command);
         terminalThread.CancelAsync();
     }
     else
     {
         try
         {
             ssh   = new SshStream(host, user, password);
             abort = false;
             stopWatch.Start();
             terminalThread.RunWorkerAsync();
             checkThread.RunWorkerAsync();
             ssh.Write(command);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Minion - Stream Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Beispiel #5
0
        private void RebButton_Click(object sender, EventArgs e)
        {
            DialogResult Result = MessageBox.Show("Are you sure you wish to reboot?", "Warning", MessageBoxButtons.YesNo);

            if (Result == DialogResult.Yes)
            {
                host = DefaultIP.Text;
                SshStream ssh     = new SshStream(host, user, pass);
                string    command = "reboot";
                ssh.Write(command);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Demonstrates the SshStream class
        /// </summary>
        public static void SshStream()
        {
            GetInput();

            try
            {
                Console.Write("-Connecting...");
                SshStream ssh = new SshStream(host, user, pass);
                Console.WriteLine("OK ({0}/{1})", ssh.Cipher, ssh.Mac);
                Console.WriteLine("Server version={0}, Client version={1}", ssh.ServerVersion, ssh.ClientVersion);
                Console.WriteLine("-Use the 'exit' command to disconnect.");
                Console.WriteLine();

                //Sets the end of response character
                ssh.Prompt = "#";
                //Remove terminal emulation characters
                ssh.RemoveTerminalEmulationCharacters = true;

                //Reads the initial response from the SSH stream
                Console.Write(ssh.ReadResponse());

                //Send commands from the user
                while (true)
                {
                    string command = Console.ReadLine();
                    if (command.ToLower().Equals("exit"))
                    {
                        break;
                    }

                    //Write command to the SSH stream
                    ssh.Write(command);
                    //Read response from the SSH stream
                    Console.Write(ssh.ReadResponse());
                }
                ssh.Close();                 //Close the connection
                Console.WriteLine("Connection closed.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #7
0
 private void btbReboot_Click(object sender, EventArgs e)
 {
     ssh = new SshStream(txtIP.Text, txtUsername.Text, txtPassword.Text);
     ssh.Write("reboot");
     ReadSSH();
 }
Beispiel #8
0
 private void btnSend_Click(object sender, EventArgs e)
 {
     ssh.Write(txtCommand.Text);
     ReadSSH();
 }