Package com.jcraft.jsch

Examples of com.jcraft.jsch.JSchException


    String remoteFilePath = remoteFileInfo.filePath;
    String tempRemotePath = tempNameForSourceFile(remoteFilePath);
    File localFile = null;
    long bytesCopied = 0L;
    IOException cleanupIOException = null;
    JSchException cleanupJSchException = null;
    boolean success = false;
   
    // Copy file and validate result
    try {
      // Rename the remote file with a temporary name before copying 
      if(logger.isDebugEnabled()) {
        logger.debug("Renaming remote file to: {}", tempRemotePath);
      }
      sshCommand.execShellCommand("mv " + remoteFilePath + " " + tempRemotePath);

      // Copy the (renamed) remote file to local destination
      remoteFileInfo.filePath = tempRemotePath;  // remote file name is needed during validation
      bytesCopied = sshCommand.copyFrom(tempRemotePath, localFilePath);
      localFile = new File(localFilePath);
      long modTime =  (long) (Double.parseDouble(remoteFileInfo.fileModtime) * 1000.0);
      localFile.setLastModified(modTime);
     
      // Check integrity of copy
      success = validateRemoteFileCopy(sshCommand, remoteFileInfo, localFilePath);
      if (!success) {
        logger.warn("Copy of file {} did not pass integrity check!", remoteFilePath);
      }
    } catch (IOException ex) {
      // If there's been an error copying the file, we may be left with a zero-length or incomplete file
      if ((localFile != null) && localFile.exists() && !success) {
        if(logger.isDebugEnabled()) {
          logger.debug("Deleting failed local copy of remote file: {}", localFile.getAbsolutePath());
        }
        localFile.delete();
      }
    } finally {
      // Use a try-block during cleanup, but only throw exception if the
      // main file-copy try-block doesn't
      try {
        if (deleteSource && success) {
          if(logger.isDebugEnabled()) {
            logger.debug("Deleting remote file: {}", tempRemotePath);
          }
          sshCommand.execShellCommand("rm " + tempRemotePath);
        } else {
          // Move source file back from temporary name
          sshCommand.execShellCommand("mv " + tempRemotePath + " " + remoteFilePath);
        }
      } catch (JSchException ex) {
        logger.warn("JSchException during remote file copy cleanup: {}", ex);
        cleanupJSchException = new JSchException(ex.getMessage());       
      } catch (IOException ex) {
        logger.warn("IOException during remote file copy cleanup: {}", ex);
        cleanupIOException = new IOException(ex);
      }
      remoteFileInfo.filePath = remoteFilePath;  // restore original file name in argument
View Full Code Here


  }
 
  private static String execTailOnRemoteFile(SSHCommand sshCommand, String remoteFilePath, int numLines) throws JSchException, IOException
  {
    if ((sshCommand == null) || !sshCommand.isConnected()) {
      throw new JSchException("Not connected with a valid SSH session");
    }
    String numLinesArg = String.valueOf(numLines);
    if ((numLines < 0) || (numLinesArg == null) || (numLinesArg.length() == 0) || (remoteFilePath == null) || (remoteFilePath.length() == 0)) {
      return null;
    } else if (numLines == 0) {
View Full Code Here

            if (credential == null) {
                try {
                    credential = getCredential();
                } catch (SecurityException t) {
                    System.out.printf("Could not get proxy: %s: %s\n", t.getClass().getSimpleName(), t.getMessage());
                    throw new JSchException(t.toString());
                }
            }

            String cname = host;

            try {
                cname = InetAddress.getByName(cname).getCanonicalHostName();
            } catch (UnknownHostException e) {
            }

            GSSName name = HostAuthorization.getInstance().getExpectedName(credential, cname);

//      context = manager.createContext(name, null, credential, GSSContext.DEFAULT_LIFETIME);
//
//      // RFC4462 3.4. GSS-API Session
//      //
//      // When calling GSS_Init_sec_context(), the client MUST set
//      // integ_req_flag to "true" to request that per-message integrity
//      // protection be supported for this context. In addition,
//      // deleg_req_flag MAY be set to "true" to request access delegation,
//      // if
//      // requested by the user.
//      //
//      // Since the user authentication process by its nature authenticates
//      // only the client, the setting of mutual_req_flag is not needed for
//      // this process. This flag SHOULD be set to "false".
//
//      // TODO: OpenSSH's sshd does accept 'false' for mutual_req_flag
//      // context.requestMutualAuth(false);
//      context.requestMutualAuth(true);
//      context.requestConf(true);
//      context.requestInteg(true); // for MIC
//      context.requestCredDeleg(true);
//      context.requestAnonymity(false);

            context = new BCGSSContextImpl(name, (GlobusGSSCredentialImpl) credential);
            context.requestLifetime(GSSCredential.DEFAULT_LIFETIME);
            context.requestCredDeleg(true);
            context.requestMutualAuth(true);
            context.requestReplayDet(true);
            context.requestSequenceDet(true);
            context.requestConf(false);
            context.requestInteg(true);
            ((ExtendedGSSContext)context).setOption(GSSConstants.DELEGATION_TYPE, GSIConstants.DELEGATION_TYPE_FULL);

            return;
        } catch (GSSException ex) {
            throw new JSchException(ex.toString());
        }
    }
View Full Code Here

    public byte[] init(byte[] token, int s, int l) throws JSchException {
        try {
            return context.initSecContext(token, s, l);
        } catch (GSSException ex) {
            throw new JSchException(ex.toString());
        }
    }
View Full Code Here

      context.requestAnonymity(false);

      return;
    }
    catch(GSSException ex){
      throw new JSchException(ex.toString());
    }
  }
View Full Code Here

        setSystemProperty(pUseSubjectCredsOnly, "false");
      }
      return context.initSecContext(token, 0, l);
    }
    catch(GSSException ex){
      throw new JSchException(ex.toString());
    }
    catch(java.lang.SecurityException ex){
      throw new JSchException(ex.toString());
    }
    finally{
      if(useSubjectCredsOnly==null){
        // By the default, it must be "true".
        setSystemProperty(pUseSubjectCredsOnly, "true");
View Full Code Here

              monitor);
        } catch (JSchException e) {
          throw e;
        }
        if (session == null) {
          throw new JSchException(Messages.SSHTunnelSession_0
              + hostname);
        }
        if (session.getTimeout() != DEFAULT_TIMEOUT) {
          session.setTimeout(DEFAULT_TIMEOUT);
        }
View Full Code Here

   public void testPropateConvertsAuthException() {
      ssh.propagate(new JSchException("Auth fail"), "");
   }

   public void testExceptionClassesRetry() {
      assert ssh.shouldRetry(new JSchException("io error", new IOException("socket closed")));
      assert ssh.shouldRetry(new JSchException("connect error", new ConnectException("problem")));
      assert ssh.shouldRetry(new IOException("channel %s is not open", new NullPointerException()));
      assert ssh.shouldRetry(new IOException("channel %s is not open", new NullPointerException(null)));
   }
View Full Code Here

   }

   public void testExceptionMessagesRetry() {
      assert !ssh.shouldRetry(new NullPointerException(""));
      assert !ssh.shouldRetry(new NullPointerException((String) null));
      assert ssh.shouldRetry(new JSchException("Session.connect: java.io.IOException: End of IO Stream Read"));
      assert ssh.shouldRetry(new JSchException("Session.connect: invalid data"));
      assert ssh.shouldRetry(new JSchException("Session.connect: java.net.SocketException: Connection reset"));
   }
View Full Code Here

      assert !ssh.shouldRetry(new SftpException(ChannelSftp.SSH_FX_FAILURE, new NullPointerException().toString()));
   }

   public void testCausalChainHasMessageContaining() {
      assert ssh.causalChainHasMessageContaining(
            new JSchException("Session.connect: java.io.IOException: End of IO Stream Read")).apply(
            " End of IO Stream Read");
      assert ssh.causalChainHasMessageContaining(new JSchException("Session.connect: invalid data")).apply(
            " invalid data");
      assert ssh.causalChainHasMessageContaining(
            new JSchException("Session.connect: java.net.SocketException: Connection reset")).apply("java.net.Socket");
      assert !ssh.causalChainHasMessageContaining(new NullPointerException()).apply(" End of IO Stream Read");
   }
View Full Code Here

TOP

Related Classes of com.jcraft.jsch.JSchException

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.