Package com.trilead.ssh2

Examples of com.trilead.ssh2.Session


          pfleCommandFile = fleResultFile;
        }
      }

      // set execute permissions for owner
      SFTPv3FileHandle fileHandle = this.getFileHandle(strFileName, new Integer(0700));

      FileInputStream fis = null;
      long offset = 0;
      try {
        fis = new FileInputStream(pfleCommandFile);
View Full Code Here


    @SuppressWarnings("unused")
    final String conMethodName = conClassName + "::setFilePermissions";

    SFTPv3FileAttributes attr = new SFTPv3FileAttributes();
    attr.permissions = pintPermissions;
    SFTPv3FileHandle fileHandle = this.FtpClient().createFileTruncate(pstrFileName, attr);
    return fileHandle;
  } // private void setFilePermissions
View Full Code Here

    @SuppressWarnings("unused")
    final String conMethodName = conClassName + "::setFilePermissions";

    SFTPv3FileAttributes attr = new SFTPv3FileAttributes();
    attr.permissions = pintPermissions;
    @SuppressWarnings("unused")
    SFTPv3FileHandle fileHandle = this.FtpClient().createFileTruncate(pstrFileName, attr);
  } // private void setFilePermissions
View Full Code Here

          commandFile = resultFile;
        }
      }

      // set execute permissions for owner
      SFTPv3FileHandle fileHandle = sftpClient.createFileTruncate(commandFile.getName(), attr);

      FileInputStream fis = null;
      long offset = 0;
      try {
        fis = new FileInputStream(commandFile);
View Full Code Here

 
  public long putFile(String localFile, String remoteFile) throws Exception {
    try{
      remoteFile = resolvePathname(remoteFile);     
      SFTPv3FileHandle fileHandle = sftpClient.createFileTruncate(remoteFile);
      File localF = new File(localFile);
      FileInputStream fis = null;
      long offset = 0;
            try {
                fis = new FileInputStream(localF);
View Full Code Here

   * @see #get( String, String )
   * @exception Exception
   */
  public long getFile(String remoteFile, String localFile, boolean append) throws Exception {
    String sourceLocation = resolvePathname(remoteFile);
    SFTPv3FileHandle sftpFileHandle = null;
        FileOutputStream fos            = null;
        File transferFile               = null;
        long remoteFileSize             = -1;
       
        try {
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

TOP

Related Classes of com.trilead.ssh2.Session

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.