Search in sources :

Example 1 with SysFtpVO

use of com.netsteadfast.greenstep.vo.SysFtpVO in project bamboobsc by billchen198318.

the class SystemFtpClientUtils method findSysFtp.

public static SysFtpVO findSysFtp(String ftpId) throws ServiceException, Exception {
    SysFtpVO ftp = new SysFtpVO();
    ftp.setId(ftpId);
    DefaultResult<SysFtpVO> result = sysFtpService.findByUK(ftp);
    if (result.getValue() == null) {
        throw new ServiceException(result.getSystemMessage().getValue());
    }
    ftp = result.getValue();
    return ftp;
}
Also used : ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysFtpVO(com.netsteadfast.greenstep.vo.SysFtpVO)

Example 2 with SysFtpVO

use of com.netsteadfast.greenstep.vo.SysFtpVO in project bamboobsc by billchen198318.

the class SystemFtpClientUtils method getFilesByFtp.

private static void getFilesByFtp(SystemFtpClientResultObj resultObj) throws Exception {
    SysFtpVO ftp = resultObj.getSysFtp();
    SysFtpTranVO tran = resultObj.getSysFtpTran();
    FtpClientUtils ftpClient = new FtpClientUtils();
    File storeDir = getStoreDir();
    try {
        ftpClient.login(ftp.getAddress(), ftp.getUser(), ftp.getPass());
        for (String name : resultObj.getNames()) {
            ftpClient.get(tran.getCwd(), storeDir, name);
        }
        fillStoreDirFiles(storeDir, resultObj);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    } finally {
        storeDir = null;
        ftpClient.close();
        ftpClient = null;
    }
}
Also used : SysFtpTranVO(com.netsteadfast.greenstep.vo.SysFtpTranVO) File(java.io.File) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysFtpVO(com.netsteadfast.greenstep.vo.SysFtpVO)

Example 3 with SysFtpVO

use of com.netsteadfast.greenstep.vo.SysFtpVO in project bamboobsc by billchen198318.

the class SystemFtpClientUtils method getFileOnly.

/**
	 * 取出FTP或SFTP上的檔案
	 * 
	 * @param tranId	TB_SYS_FTP_TRAN.TRAN_ID
	 * @return
	 * @throws ServiceException
	 * @throws Exception
	 */
public static SystemFtpClientResultObj getFileOnly(String tranId) throws ServiceException, Exception {
    if (StringUtils.isBlank(tranId)) {
        throw new Exception(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    logger.info("getFileOnly begin...");
    SystemFtpClientResultObj resultObj = new SystemFtpClientResultObj();
    SysFtpTranVO tran = findSysFtpTran(tranId);
    SysFtpVO ftp = findSysFtp(tran.getFtpId());
    List<TbSysFtpTranSegm> segms = findSysFtpTranSegm(tran.getFtpId(), tran.getTranId());
    resultObj.setSysFtp(ftp);
    resultObj.setSysFtpTran(tran);
    resultObj.setSysFtpTranSegms(segms);
    getFiles(resultObj);
    logger.info("getFileOnly end...");
    return resultObj;
}
Also used : TbSysFtpTranSegm(com.netsteadfast.greenstep.po.hbm.TbSysFtpTranSegm) SysFtpTranVO(com.netsteadfast.greenstep.vo.SysFtpTranVO) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SystemFtpClientResultObj(com.netsteadfast.greenstep.model.SystemFtpClientResultObj) SysFtpVO(com.netsteadfast.greenstep.vo.SysFtpVO)

Example 4 with SysFtpVO

use of com.netsteadfast.greenstep.vo.SysFtpVO in project bamboobsc by billchen198318.

the class SystemFtpClientUtils method putFiles.

/**
	 * 放檔案至FTP或SFTP上
	 * 
	 * @param tranId	TB_SYS_FTP_TRAN.TRAN_ID
	 * @return
	 * @throws ServiceException
	 * @throws Exception
	 */
public static boolean putFiles(String tranId) throws ServiceException, Exception {
    if (StringUtils.isBlank(tranId)) {
        throw new Exception(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    SysFtpTranVO tran = findSysFtpTran(tranId);
    SysFtpVO ftp = findSysFtp(tran.getFtpId());
    if (!SystemFtpClientModel.TRAN_PUT.equals(tran.getTranType())) {
        logger.warn("Not a PUT mode TB_SYS_FTP_TRAN.TRAN_ID: " + tranId);
        return false;
    }
    /**
		 * 這裡的 NAME_EXPRESSION 回傳的 names 檔案文字路徑必須 如 : /var/upload/20150514.txt
		 * **不可** 是 20150514.txt
		 */
    List<String> fileFullPathNames = getFileNames(tran.getExprType(), tran.getNameExpression());
    if (SystemFtpClientModel.FTP.equals(ftp.getType())) {
        // FTP
        putFilesByFtp(ftp, tran, fileFullPathNames);
    } else {
        // SFTP
        putFileBySFtp(ftp, tran, fileFullPathNames);
    }
    return true;
}
Also used : SysFtpTranVO(com.netsteadfast.greenstep.vo.SysFtpTranVO) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysFtpVO(com.netsteadfast.greenstep.vo.SysFtpVO)

Example 5 with SysFtpVO

use of com.netsteadfast.greenstep.vo.SysFtpVO in project bamboobsc by billchen198318.

the class SystemFtpClientUtils method getFilesBySFtp.

private static void getFilesBySFtp(SystemFtpClientResultObj resultObj) throws Exception {
    SysFtpVO ftp = resultObj.getSysFtp();
    File storeDir = getStoreDir();
    List<String> localFile = new ArrayList<String>();
    for (String name : resultObj.getNames()) {
        localFile.add(storeDir.getPath() + "/" + name);
    }
    try {
        SFtpClientUtils.get(ftp.getUser(), ftp.getPass(), ftp.getAddress(), ftp.getPort(), resultObj.getNames(), localFile);
        fillStoreDirFiles(storeDir, resultObj);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    } finally {
        storeDir = null;
    }
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysFtpVO(com.netsteadfast.greenstep.vo.SysFtpVO)

Aggregations

ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)5 SysFtpVO (com.netsteadfast.greenstep.vo.SysFtpVO)5 IOException (java.io.IOException)4 SysFtpTranVO (com.netsteadfast.greenstep.vo.SysFtpTranVO)3 File (java.io.File)2 SystemFtpClientResultObj (com.netsteadfast.greenstep.model.SystemFtpClientResultObj)1 TbSysFtpTranSegm (com.netsteadfast.greenstep.po.hbm.TbSysFtpTranSegm)1 ArrayList (java.util.ArrayList)1