压缩包上传到sftp服务器

public String uploadQyKsPhotoZip(File zipfile, String path, String filename,String jdjhid){
List<String> list=new ArrayList<String>();
String pathName="/zynl/osta/"+DateUtils.format(new Date(),"yyyy")+"/";
try {
ZipFile zf = new ZipFile(zipfile);
for (Enumeration entries = zf.getEntries(); entries
.hasMoreElements();) {
ZipEntry entry = ((ZipEntry) entries.nextElement());
String zipEntryName = entry.getName();
String zipname=zipEntryName.substring(0,zipEntryName.lastIndexOf("/")+1);
String zipEntryNamep=zipEntryName.substring(zipEntryName.indexOf("/")+1,zipEntryName.length());
InputStream is = zf.getInputStream(entry);
if(!(zipEntryName.equals(zipname))){
String idno=zipEntryNamep.substring(0,18);;
System.out.println(idno);
List<OsipOstaKsinfo> li=ksinfoDao.findBy("credennum", idno);
if(li.size()>0){

FjxxbVO fjxx = new FjxxbVO();
String fileName= this.getRandomName(zipEntryNamep);
boolean isOk=SftpUtils.uploadInputStream(pathName, is, fileName);
if(isOk){
fjxx.setSsmc(fileName);
fjxx.setFId(jdjhid); // 外键
fjxx.setZbm("OSIP_OSTA_KSBM");//表名
fjxx.setCreated(new Date()); // 创建时间
fjxx.setLj(pathName); // 文件名称
fjxx.setWjmc(zipEntryNamep); // 程式名称

fjxxService.addFjxx(fjxx);//保存附件信息表
OsipOstaKsinfo bo=li.get(0);
//System.out.println("test/"+jdjhid+"/"+zipEntryName);
bo.setPhoto(fjxx.getId());
ksinfoDao.update(bo);
try {
OsipOstaKsbm ksbm = ksbmDao.getOsipOstaKsbmByKsidAndJdjhid(jdjhid, bo.getId());
if(ksbm!=null){
ksbm.setPhoto(fjxx.getId());
ksbmDao.updateKsbmQy(ksbm.getPhoto(), jdjhid, bo.getId());
}
} catch (Exception e) {
e.printStackTrace();
}

}
}else{
list.add(zipEntryName);

}
}

}

} catch (IOException e) {
e.printStackTrace();
}

return StringUtils.join(list, ",");
}

posted on 2017-07-14 09:21  王宏伟的博客  阅读(372)  评论(0编辑  收藏  举报