|
@@ -1,5 +1,7 @@
|
|
|
package com.jjt.out.service.impl;
|
|
|
|
|
|
+import cn.hutool.extra.ftp.Ftp;
|
|
|
+import cn.hutool.extra.ftp.FtpMode;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.jjt.common.constant.Constants;
|
|
@@ -58,10 +60,16 @@ public class OutProcessServiceImpl extends OutBaseService implements IOutProcess
|
|
|
if (files != null && files.length > 0) {
|
|
|
Arrays.sort(files, Comparator.comparing(File::getName));
|
|
|
}
|
|
|
+ if (!ftpUtil.getDir().endsWith(Constants.DIR_END)) {
|
|
|
+ ftpUtil.setDir(ftpUtil.getDir() + "/");
|
|
|
+ }
|
|
|
+ try (Ftp ftp = new Ftp(ftpUtil.getIp(), ftpUtil.getPort() == null ? 21 : ftpUtil.getPort(), ftpUtil.getUser(), ftpUtil.getPass())) {
|
|
|
+
|
|
|
+ // 设置传输模式为被动模式(可根据需要修改)
|
|
|
+ ftp.setMode(FtpMode.Passive);
|
|
|
|
|
|
- for (File file : files) {
|
|
|
- //获取文件同步顺序,如果报错,则不同步
|
|
|
- try {
|
|
|
+ for (File file : files) {
|
|
|
+ //获取文件同步顺序,如果报错,则不同步
|
|
|
//校验JSON文件名格式
|
|
|
if (!file.getName().startsWith("sync-")) {
|
|
|
continue;
|
|
@@ -75,7 +83,7 @@ public class OutProcessServiceImpl extends OutBaseService implements IOutProcess
|
|
|
if (md5.equals(desc.getMd5())) {
|
|
|
Date start = new Date();
|
|
|
//上传json文件
|
|
|
- boolean flag = ftpUtil.upload(file);
|
|
|
+ boolean flag = ftp.upload(ftpUtil.getDir(), file);
|
|
|
boolean flag1 = false;
|
|
|
//上传zip文件
|
|
|
List<File> list = new ArrayList<>();
|
|
@@ -85,13 +93,13 @@ public class OutProcessServiceImpl extends OutBaseService implements IOutProcess
|
|
|
//如果是分卷压缩文件,则需要读取所有文件名上传
|
|
|
list = zipFile.getSplitZipFiles();
|
|
|
for (File f : list) {
|
|
|
- flag1 = flag && ftpUtil.upload(f);
|
|
|
+ flag1 = flag && ftp.upload(ftpUtil.getDir(), f);
|
|
|
}
|
|
|
} else {
|
|
|
- flag1 = ftpUtil.upload(zipFile.getFile());
|
|
|
+ flag1 = ftp.upload(ftpUtil.getDir(), zipFile.getFile());
|
|
|
}
|
|
|
} else {
|
|
|
- flag1 = ftpUtil.upload(syncFile);
|
|
|
+ flag1 = ftp.upload(ftpUtil.getDir(), syncFile);
|
|
|
}
|
|
|
|
|
|
Date end = new Date();
|
|
@@ -118,11 +126,11 @@ public class OutProcessServiceImpl extends OutBaseService implements IOutProcess
|
|
|
info.setUploadStatus(status);
|
|
|
syncInfoService.insertOutSyncInfo(info);
|
|
|
} else {
|
|
|
- log.error("这个是错误滴" + desc.toString());
|
|
|
+ log.error("MD5校验未成功,暂时不上传" + desc.toString());
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("上传出错啦{}", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|