Example #1
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
 public string Connect(string host, string username, string password)
 {
     _sshStream = new SshStream(host, username, password)
                      {
                          RemoveTerminalEmulationCharacters = true,
                          Prompt = @"\[[^@]*@[^]]*]\s>\s?$"
                      };
     return _sshStream.ReadResponse();
 }
Example #3
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);
            }
        }
Example #4
0
 private void ReadSSH()
 {
     System.Threading.Thread.Sleep(100);
     txtConsole.Text += ssh.ReadResponse() + Environment.NewLine;
 }