Package ch.ethz.ssh2

Examples of ch.ethz.ssh2.StreamGobbler


         *
         * AUTHENTICATION OK. DO SOMETHING.
         *
         */

        Session sess = conn.openSession();

        int x_width = 90;
        int y_width = 30;

        sess.requestPTY("dumb", x_width, y_width, 0, 0, null);
        sess.startShell();

        TerminalDialog td = new TerminalDialog(loginFrame, username + "@" + hostname, sess, x_width, y_width);

        /* The following call blocks until the dialog has been closed */

 
View Full Code Here


      if (isAuthenticated == false)
        throw new IOException("Authentication failed.");

      /* Create a session */

      Session sess = conn.openSession();

      sess.execCommand("uname -a && date && uptime && who");

      System.out.println("Here is some information about the remote host:");

      /*
       * This basic example does not handle stderr, which is sometimes dangerous
       * (please read the FAQ).
       */

      InputStream stdout = new StreamGobbler(sess.getStdout());

      BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

      while (true)
      {
        String line = br.readLine();
        if (line == null)
          break;
        System.out.println(line);
      }

      /* Show exit status, if available (otherwise "null") */

      System.out.println("ExitCode: " + sess.getExitStatus());

      /* Close this session */

      sess.close();

      /* Close the connection */

      conn.close();

 
View Full Code Here

      if (isAuthenticated == false)
        throw new IOException("Authentication failed.");

      /* Create a session */

      Session sess = conn.openSession();

      sess.execCommand("echo \"Text on STDOUT\"; echo \"Text on STDERR\" >&2");

      InputStream stdout = new StreamGobbler(sess.getStdout());
      InputStream stderr = new StreamGobbler(sess.getStderr());
 
      BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout));
      BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr));
     
      System.out.println("Here is the output from stdout:");
 
      while (true)
      {
        String line = stdoutReader.readLine();
        if (line == null)
          break;
        System.out.println(line);
      }
     
      System.out.println("Here is the output from stderr:");
     
      while (true)
      {
        String line = stderrReader.readLine();
        if (line == null)
          break;
        System.out.println(line);
      }
     
      /* Close this session */
     
      sess.close();

      /* Close the connection */

      conn.close();

 
View Full Code Here

      if (isAuthenticated == false)
        throw new IOException("Authentication failed.");

      /* Create a session */

      Session sess = conn.openSession();

      sess.execCommand("uname -a && date && uptime && who");

      InputStream stdout = new StreamGobbler(sess.getStdout());
      BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

      System.out.println("Here is some information about the remote host:");

      while (true)
      {
        String line = br.readLine();
        if (line == null)
          break;
        System.out.println(line);
      }

      /* Close this session */

      sess.close();

      /* Close the connection */

      conn.close();

 
View Full Code Here

      if (isAuthenticated == false)
        throw new IOException("Authentication failed.");

      /* Create a session */

      Session sess = conn.openSession();

      sess.execCommand("uname -a && date && uptime && who");

      InputStream stdout = new StreamGobbler(sess.getStdout());

      BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

      System.out.println("Here is some information about the remote host:");

      while (true)
      {
        String line = br.readLine();
        if (line == null)
          break;
        System.out.println(line);
      }

      /* Close this session */
     
      sess.close();

      /* Close the connection */

      conn.close();

 
View Full Code Here

   * \return boolean
   *
   * @return
   */
  public boolean remoteIsWindowsShell() {
    Session objSSHSession = null;
    flgIsRemoteOSWindows = false;

    try {
      // TODO the testcommand should be defined by an option
      String checkShellCommand = "echo %ComSpec%";
      logger.debug("Opening new session...");
      objSSHSession = this.getSshConnection().openSession();
      logger.debug("Executing command " + checkShellCommand);
      objSSHSession.execCommand(checkShellCommand);

      logger.debug("output to stdout for remote command: " + checkShellCommand);
      ipsStdOut = new StreamGobbler(objSSHSession.getStdout());
      ipsStdErr = new StreamGobbler(objSSHSession.getStderr());
      BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(ipsStdOut));
      String stdOut = "";
      while (true) {
        String line = stdoutReader.readLine();
        if (line == null)
          break;
        logger.debug(line);
        stdOut += line;
      }
      logger.debug("output to stderr for remote command: " + checkShellCommand);
      BufferedReader stderrReader = new BufferedReader(new InputStreamReader(ipsStdErr));
      while (true) {
        String line = stderrReader.readLine();
        if (line == null)
          break;
        logger.debug(line);
      }
      // TODO The expected result-string for testing the os should be defined by an option
      if (stdOut.indexOf("cmd.exe") > -1) {
        logger.debug("Remote shell is a Windows shell.");
        flgIsRemoteOSWindows = true;
        return true;
      }
      else {
        logger.debug("Remote shell is a Linux/Unix shell.");
      }
    }
    catch (Exception e) {
      logger.debug("Failed to check if remote system is windows shell: " + e);
    }
    finally {
      if (objSSHSession != null)
        try {
          objSSHSession.close();
        }
        catch (Exception e) {
          logger.debug("Failed to close session: ", e);
        }
    }
View Full Code Here

      /*
       * This basic example does not handle stderr, which is sometimes dangerous
       * (please read the FAQ).
       */

      InputStream stdout = new StreamGobbler(sess.getStdout());

      BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

      while (true)
      {
View Full Code Here

      /*
       * This basic example does not handle stderr, which is sometimes dangerous
       * (please read the FAQ).
       */

      InputStream stdout = new StreamGobbler(sess.getStdout());

      BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

      while (true)
      {
View Full Code Here

      Session sess = conn.openSession();

      sess.execCommand("echo \"Text on STDOUT\"; echo \"Text on STDERR\" >&2");

      InputStream stdout = new StreamGobbler(sess.getStdout());
      InputStream stderr = new StreamGobbler(sess.getStderr());
 
      BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout));
      BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr));
     
      System.out.println("Here is the output from stdout:");
View Full Code Here

      Session sess = conn.openSession();

      sess.execCommand("uname -a && date && uptime && who");

      InputStream stdout = new StreamGobbler(sess.getStdout());
      BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

      System.out.println("Here is some information about the remote host:");

      while (true)
View Full Code Here

TOP

Related Classes of ch.ethz.ssh2.StreamGobbler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.