|
|
@ -7,6 +7,7 @@ import java.sql.Timestamp;
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
|
|
|
import cn.hutool.extra.ftp.Ftp;
|
|
|
|
import cn.hutool.extra.ssh.JschUtil;
|
|
|
|
import cn.hutool.extra.ssh.JschUtil;
|
|
|
|
import cn.hutool.extra.ssh.Sftp;
|
|
|
|
import cn.hutool.extra.ssh.Sftp;
|
|
|
|
import cn.hutool.system.OsInfo;
|
|
|
|
import cn.hutool.system.OsInfo;
|
|
|
@ -84,6 +85,7 @@ public class DownloadSFTPFileTask {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void runTask(RemoteRecord resources) {
|
|
|
|
private void runTask(RemoteRecord resources) {
|
|
|
|
|
|
|
|
resources.setOperation(resources.getOperation() + FILE_NAME_SPLIT + resources.getUploadRemoteTaskName());
|
|
|
|
// 更新一条记录,然后状态为待取回状态
|
|
|
|
// 更新一条记录,然后状态为待取回状态
|
|
|
|
RemoteRecordDto remoteRecordDto = remoteRecordService.create(resources);
|
|
|
|
RemoteRecordDto remoteRecordDto = remoteRecordService.create(resources);
|
|
|
|
// 然后调用sftp进行取回
|
|
|
|
// 然后调用sftp进行取回
|
|
|
@ -116,13 +118,13 @@ public class DownloadSFTPFileTask {
|
|
|
|
|
|
|
|
|
|
|
|
remoteRecordService.update(remoteRecord);
|
|
|
|
remoteRecordService.update(remoteRecord);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// sftp.close();
|
|
|
|
// fixme 更新失败补充推送费用
|
|
|
|
// fixme 更新失败补充推送费用
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String sftpToDownloadFile(String sftpFilePath, RemoteRecord resources) {
|
|
|
|
private String sftpToDownloadFile(String sftpFilePath, RemoteRecord resources) {
|
|
|
|
|
|
|
|
|
|
|
|
// 准备sftp配置
|
|
|
|
// 准备sftp配置
|
|
|
|
Session session = JschUtil.getSession(REMOTE_TRANS_HOST, REMOTE_TRANS_PORT, REMOTE_TRANS_SSH_USER, REMOTE_TRANS_SSH_PW);
|
|
|
|
Session session = JschUtil.createSession(REMOTE_TRANS_HOST, REMOTE_TRANS_PORT, REMOTE_TRANS_SSH_USER, REMOTE_TRANS_SSH_PW);
|
|
|
|
Sftp sftp = JschUtil.createSftp(session);
|
|
|
|
Sftp sftp = JschUtil.createSftp(session);
|
|
|
|
|
|
|
|
|
|
|
|
// 构建输出
|
|
|
|
// 构建输出
|
|
|
@ -136,11 +138,11 @@ public class DownloadSFTPFileTask {
|
|
|
|
resources.setLocalSavePath(localSavePath);
|
|
|
|
resources.setLocalSavePath(localSavePath);
|
|
|
|
log.info(" ====== [DownloadSFTPFileTask|sftpToDownloadFiles , ftpFilePath is {} ] ======", sftpFilePath);
|
|
|
|
log.info(" ====== [DownloadSFTPFileTask|sftpToDownloadFiles , ftpFilePath is {} ] ======", sftpFilePath);
|
|
|
|
// SFTP 进行下载
|
|
|
|
// SFTP 进行下载
|
|
|
|
sftp.download(sftpFilePath, FileUtil.file(localSavePath));
|
|
|
|
sftp.get(sftpFilePath, localSavePath);
|
|
|
|
sftp.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sftp.close();
|
|
|
|
|
|
|
|
// sftp.download(sftpFilePath, FileUtil.file(localSavePath));
|
|
|
|
return localSavePath;
|
|
|
|
return localSavePath;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -155,23 +157,24 @@ public class DownloadSFTPFileTask {
|
|
|
|
String dirPath;
|
|
|
|
String dirPath;
|
|
|
|
// 生成一个随机文件夹目录,方便整理和打包
|
|
|
|
// 生成一个随机文件夹目录,方便整理和打包
|
|
|
|
|
|
|
|
|
|
|
|
String filePath = RandomUtil.randomString(6) + FILE_NAME_SPLIT + baseStr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (osInfo.isWindows()) {
|
|
|
|
if (osInfo.isWindows()) {
|
|
|
|
dirPath = remoteLinkFileBasePathWindows + timeFormate + File.separator;
|
|
|
|
dirPath = remoteLinkFileBasePathWindows + timeFormate + File.separator;
|
|
|
|
|
|
|
|
log.info("=========== [dirPath is {} ] =========== ", dirPath);
|
|
|
|
FileUtil.mkdir(new File(dirPath));
|
|
|
|
FileUtil.mkdir(new File(dirPath));
|
|
|
|
// 构建存储文件
|
|
|
|
// 构建存储文件
|
|
|
|
return dirPath + filePath;
|
|
|
|
return dirPath + baseStr;
|
|
|
|
} else if (osInfo.isLinux()) {
|
|
|
|
} else if (osInfo.isLinux()) {
|
|
|
|
dirPath = remoteLinkFileBasePathLinux + timeFormate + File.separator;
|
|
|
|
dirPath = remoteLinkFileBasePathLinux + timeFormate + File.separator;
|
|
|
|
|
|
|
|
log.info("=========== [dirPath is {} ] =========== ", dirPath);
|
|
|
|
FileUtil.mkdir(new File(dirPath));
|
|
|
|
FileUtil.mkdir(new File(dirPath));
|
|
|
|
// 构建存储文件
|
|
|
|
// 构建存储文件
|
|
|
|
return dirPath + filePath;
|
|
|
|
return dirPath + baseStr;
|
|
|
|
} else if (osInfo.isMac()) {
|
|
|
|
} else if (osInfo.isMac()) {
|
|
|
|
dirPath = remoteLinkFileBasePathMac + timeFormate + File.separator;
|
|
|
|
dirPath = remoteLinkFileBasePathMac + timeFormate + File.separator;
|
|
|
|
|
|
|
|
log.info("=========== [dirPath is {} ] =========== ", dirPath);
|
|
|
|
FileUtil.mkdir(new File(dirPath));
|
|
|
|
FileUtil.mkdir(new File(dirPath));
|
|
|
|
// 构建存储文件
|
|
|
|
// 构建存储文件
|
|
|
|
return dirPath + filePath;
|
|
|
|
return dirPath + baseStr;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|