Package com.trilead.ssh2.auth

Examples of com.trilead.ssh2.auth.AuthenticationManager


            }
        };
    }

    public InputStream read(String file) throws IOException {
        final SFTPv3FileHandle h = openFileRO(file);
        return new InputStream() {
            private long offset = 0;

            public int read() throws IOException {
                byte[] b = new byte[1];
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;
      }
    }
    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

      throw new Exception("Failed to kill children of pid "+pel.pid+": "+e,e);
    }
  }

  private void executeCommand(String command, int logLevel) throws Exception{
    Session session = getSshConnection().openSession();
    try{
      session.execCommand(command);
      spooler_log.log(logLevel,"output to stdout for remote command: " + command);
      stdout = new StreamGobbler(this.getSshSession().getStdout());
      stderr = new StreamGobbler(this.getSshSession().getStderr());
      BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout));

      while (true) {
        String line = stdoutReader.readLine();
        if (line == null) break;
        spooler_log.log(logLevel, line);
      }


      spooler_log.log(logLevel, "output to stderr for remote command: " + command);

      BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr));
      stderrOutput = new StringBuffer();
      while (true) {
        String line = stderrReader.readLine();
        if (line == null) break;
        spooler_log.log(logLevel,line);
        stderrOutput.append( line + "\n");
      }
    }catch(Exception e){
      throw new Exception ("Error executing command \""+command+"\": "+e,e);
    }finally{
      if (session !=null) session.close();
    }   
  }
View Full Code Here

      throw new Exception("error occurred processing parameters: " + e.getMessage());
    }
  }

  protected boolean remoteIsWindowsShell() {
    Session session = null;
    try {
      String checkShellCommand = "echo %ComSpec%";
      getLogger().debug9("Opening ssh session...");
      session = this.getSshConnection().openSession();
      getLogger().debug9("Executing command " + checkShellCommand);
      session.execCommand(checkShellCommand);

      getLogger().debug9("output to stdout for remote command: " + checkShellCommand);
      stdout = new StreamGobbler(session.getStdout());
      stderr = new StreamGobbler(session.getStderr());
      BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout));
      String stdOut = "";
      while (true) {
        String line = stdoutReader.readLine();
        if (line == null)
          break;
        getLogger().debug9(line);
        stdOut += line;
      }
      getLogger().debug9("output to stderr for remote command: " + checkShellCommand);
      // Beide StreamGobbler m�ssen hintereinander instanziiert werden
      // InputStream stderr = new StreamGobbler(this.getSshSession().getStderr());
      BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr));
      while (true) {
        String line = stderrReader.readLine();
        if (line == null)
          break;
        getLogger().debug1(line);
      }
      if (stdOut.indexOf("cmd.exe") > -1) {
        getLogger().debug3("Remote shell is Windows shell.");
        return true;
      }
    }
    catch (Exception e) {
      try {
        getLogger().warn("Failed to check if remote system is windows shell: " + e);
      }
      catch (Exception es) {
        System.out.println(" Failed to check if remote system is windows shell: " + e);
      }
    }
    finally {
      if (session != null)
        try {
          session.close();
        }
        catch (Exception e) {
          try {
            getLogger().warn("Failed to close session: " + e);
          }
View Full Code Here

   * @see jSimMacs.gromacsrun.IGromacsRun#make_ndx(java.util.List,
   *      java.util.List, java.lang.String)
   */
  public List<String> make_ndx(List<String> commands,
      List<String> ndxCommands, String groupName) throws IOException {
    Session sess = null;
    BufferedReader commandResult = null;
    try {
      sess = startProcess(commands);

      OutputStuff ndxOutput = new OutputStuff();
      ndxOutput.output(sess.getStdin(), ndxCommands);

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

      ndxCommands = GromacsCommandBuilder.getInstance()
          .createRenameGroupNdxCommand(commandResult, groupName);

    } catch (IOException e1) {
      throw e1;
    } finally {
      if (commandResult != null)
        commandResult.close();
      if (sess != null)
        sess.close();
    }
    return ndxCommands;
  }
View Full Code Here

      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)
View Full Code Here

      }

      this.getSshSession().execCommand(strCmd);

      logger.debug("output to stdout for remote command: " + strCmd);
      ipsStdOut = new StreamGobbler(this.getSshSession().getStdout());
      ipsStdErr = new StreamGobbler(this.getSshSession().getStderr());
      BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(ipsStdOut));
      strbStdoutOutput = new StringBuffer();
      while (true) {
        String line = stdoutReader.readLine();
        if (line == null)
View Full Code Here

            spooler_log.debug5("executing remote command: " + command);
            this.setSshSession(this.getSshConnection().openSession());
            this.getSshSession().execCommand(command);

            spooler_log.debug5("output to stdout for remote command: " + command);
            InputStream stdout = new StreamGobbler(this.getSshSession().getStdout());
            BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout));
            while (true) {
                String line = stdoutReader.readLine();
                if (line == null) break;
                spooler_log.info(line);
            }

            spooler_log.debug5("output to stderr for remote command: " + command);
            InputStream stderr = new StreamGobbler(this.getSshSession().getStderr());
            BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr));
            String stderrOutput = "";
            while (true) {
                String line = stderrReader.readLine();
                if (line == null) break;
View Full Code Here

      spooler_log.debug5("fetching children");
      this.getSshSession().execCommand("/bin/ps -ef");

      spooler_log.debug9("output to stdout for ps command: ");
      stdout = new StreamGobbler(this.getSshSession().getStdout());
      stderr = new StreamGobbler(this.getSshSession().getStderr());
      BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout));
      String line = stdoutReader.readLine(); //Ueberschrift
      spooler_log.debug9(line);

View Full Code Here

  private void executeCommand(String command, int logLevel) throws Exception{
    Session session = getSshConnection().openSession();
    try{
      session.execCommand(command);
      spooler_log.log(logLevel,"output to stdout for remote command: " + command);
      stdout = new StreamGobbler(this.getSshSession().getStdout());
      stderr = new StreamGobbler(this.getSshSession().getStderr());
      BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout));

      while (true) {
        String line = stdoutReader.readLine();
        if (line == null) break;
View Full Code Here

TOP

Related Classes of com.trilead.ssh2.auth.AuthenticationManager

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.