public boolean scpGet(String remoteFile, String localDir, String dst, String instanceName) {
        LOG.info("remoteFile:" + remoteFile + " localdir:" + localDir +
                " dst:" + dst + " instanceName:" + instanceName);
        LOG.info("srchost:" + srcHost + "  dsthost:" + dstHost + "  amHost:" + amHost);

        ScpFrom scpFrom = new ScpFrom(srcHost, user, password);
        ScpTo scpTo = new ScpTo(dstHost, user, password);
        Exec exec = new Exec(srcHost, user, password);

        try {
            String execCommand = "cd " + remoteFile + " && cd .. && tar -cf " + instanceName + ".tar "
                    + instanceName;
            LOG.info("execCommand1:" + execCommand);
            exec.execute(execCommand);
            LOG.info("exec success");
        } catch (Exception ex) {
            try {
                exec = new Exec(srcHost, user, oldPassword);
                String execCommand = "cd " + remoteFile + " && cd .. && tar -cf " + instanceName + ".tar "
                        + instanceName;
                LOG.info("execCommand1:" + execCommand);
                exec.execute(execCommand);
                LOG.info("exec success");
            } catch (Exception eex) {
                LOG.error(eex);
                LOG.error("username:" + user + "  password:" + password);
                return false;
            }
        }

        try {
            //
            if (!amHost.split("/")[1].equals(srcHost) && !amHost.split("/")[0].equals(srcHost)) {
                scpFrom.getRemoteFile(remoteFile + ".tar", localDir);
                LOG.info("getRemoteFile:" + remoteFile + ".tar");
            }
        } catch (Exception ex) {
            try {
                scpFrom = new ScpFrom(srcHost, user, oldPassword);
                scpFrom.getRemoteFile(remoteFile + ".tar", localDir);
                LOG.info("getRemoteFile:" + remoteFile + ".tar");
            } catch (Exception eex) {
                LOG.error(eex);
                LOG.error("username:" + user + "  password:" + password);
                return false;
            }
        }

        try {
            if (!amHost.split("/")[1].equals(dstHost) && !amHost.split("/")[0].equals(dstHost)) {
                //put file to remote
                scpTo.putFile(localDir + instanceName + ".tar", localDir);
                LOG.info("putFileToRemote:" + remoteFile + ".tar");
            }
        } catch (Exception ex) {
            try {
                scpTo = new ScpTo(srcHost, user, oldPassword);
                scpTo.putFile(remoteFile + ".tar", localDir);
                LOG.info("putFileToRemote:" + remoteFile + ".tar");
            } catch (Exception eex) {
                LOG.error(eex);
                LOG.error("username:" + user + "  password:" + oldPassword);
                return false;
            }
        }

        try {
            Exec execRemote = new Exec(dstHost, user, password);
            execRemote.execute("cd " + localDir + "  &&  tar -xf " + instanceName + ".tar");
        } catch (Exception ex) {
            try {
                Exec execRemote = new Exec(dstHost, user, oldPassword);
                execRemote.execute("cd " + localDir + "  && tar -xf " + instanceName + ".tar");
            } catch (Exception eex) {
                LOG.error(eex);
                LOG.error("username:" + user + "  password:" + oldPassword);
                return false;
            }
        }

        return true;
    }
public boolean scpGet ( String remoteFile , String localDir , String dst , String instanceName ) { LOG . info ( "remoteFile:" + remoteFile + " localdir:" + localDir + " dst:" + dst + " instanceName:" + instanceName ) ; LOG . info ( "srchost:" + srcHost + "  dsthost:" + dstHost + "  amHost:" + amHost ) ; ScpFrom scpFrom = new ScpFrom ( srcHost , user , password ) ; ScpTo scpTo = new ScpTo ( dstHost , user , password ) ; Exec exec = new Exec ( srcHost , user , password ) ; try { String execCommand = "cd " + remoteFile + " && cd .. && tar -cf " + instanceName + ".tar " + instanceName ; LOG . info ( "execCommand1:" + execCommand ) ; exec . execute ( execCommand ) ; LOG . info ( "exec success" ) ; } catch ( Exception ex ) { try { exec = new Exec ( srcHost , user , oldPassword ) ; String execCommand = "cd " + remoteFile + " && cd .. && tar -cf " + instanceName + ".tar " + instanceName ; LOG . info ( "execCommand1:" + execCommand ) ; exec . execute ( execCommand ) ; LOG . info ( "exec success" ) ; } catch ( Exception eex ) { LOG . error ( eex ) ; LOG . error ( "username:" + user + "  password:" + password ) ; return false ; } } try { if ( ! amHost . split ( "/" ) [ 1 ] . equals ( srcHost ) && ! amHost . split ( "/" ) [ 0 ] . equals ( srcHost ) ) { scpFrom . getRemoteFile ( remoteFile + ".tar" , localDir ) ; LOG . info ( "getRemoteFile:" + remoteFile + ".tar" ) ; } } catch ( Exception ex ) { try { scpFrom = new ScpFrom ( srcHost , user , oldPassword ) ; scpFrom . getRemoteFile ( remoteFile + ".tar" , localDir ) ; LOG . info ( "getRemoteFile:" + remoteFile + ".tar" ) ; } catch ( Exception eex ) { LOG . error ( eex ) ; LOG . error ( "username:" + user + "  password:" + password ) ; return false ; } } try { if ( ! amHost . split ( "/" ) [ 1 ] . equals ( dstHost ) && ! amHost . split ( "/" ) [ 0 ] . equals ( dstHost ) ) { scpTo . putFile ( localDir + instanceName + ".tar" , localDir ) ; LOG . info ( "putFileToRemote:" + remoteFile + ".tar" ) ; } } catch ( Exception ex ) { try { scpTo = new ScpTo ( srcHost , user , oldPassword ) ; scpTo . putFile ( remoteFile + ".tar" , localDir ) ; LOG . info ( "putFileToRemote:" + remoteFile + ".tar" ) ; } catch ( Exception eex ) { LOG . error ( eex ) ; LOG . error ( "username:" + user + "  password:" + oldPassword ) ; return false ; } } try { Exec execRemote = new Exec ( dstHost , user , password ) ; execRemote . execute ( "cd " + localDir + "  &&  tar -xf " + instanceName + ".tar" ) ; } catch ( Exception ex ) { try { Exec execRemote = new Exec ( dstHost , user , oldPassword ) ; execRemote . execute ( "cd " + localDir + "  && tar -xf " + instanceName + ".tar" ) ; } catch ( Exception eex ) { LOG . error ( eex ) ; LOG . error ( "username:" + user + "  password:" + oldPassword ) ; return false ; } } return true ; }
get remoteFile from specific srcHost and directory

@return true or false