天天看点

直接sftp对传pdf文件,并创建相对应的目录当日的,如:20171026

public void uploadFileToTBSftp(List<String> contractIds) throws Exception {
        Date date = new Date();
        String sftpPath  = CommonUtil.getPropertiesValue("sftp.properties", "tengbang.upload")+"/"+new SimpleDateFormat("yyyyMMdd").format(date);
        SFTPUtils sftp1 = getSftp();
        ChannelSftp sftp = sftp1.getSFTPClient();
        createDir(sftpPath, sftp);//创建路径
        sftp.cd(sftpPath);//进入路径
        OutputStream outstream = null;//一个流
        List<String> fileCodes = new ArrayList<>();
        fileCodes.add("QT15");
        try {
            for( String  contractId : contractIds ){
                    ContractInfoDTO contractInfoDTO = contractInfoService.queryContractInfoByPrimaryKey(contractId);
                    String filename = new String(contractInfoDTO.getCertificateCode()+".pdf");
                    outstream = sftp.put(filename);
                    List<AttachmentDTO>  attachmentDTOs = attachmentService.searchAttachemnt(contractInfoDTO.getId().toString(), FileUtil.TYPE_CONTRACT_FILE, fileCodes);
                    IOUtils.write(synSingleFileDownloadWorker.downloadSeaweed(attachmentDTOs.get().getFilePath()), outstream );//写
                    outstream.flush();
            }
        } catch (SftpException e) {
                    e.printStackTrace();
        }finally {
                    outstream.flush();
                    outstream.close();
                    sftp.disconnect();
        }
    }