|
|
|
|
@@ -3,7 +3,6 @@ package com.kamco.cd.training.common.utils;
|
|
|
|
|
import static java.lang.String.CASE_INSENSITIVE_ORDER;
|
|
|
|
|
|
|
|
|
|
import com.jcraft.jsch.ChannelExec;
|
|
|
|
|
import com.jcraft.jsch.ChannelSftp;
|
|
|
|
|
import com.jcraft.jsch.JSch;
|
|
|
|
|
import com.jcraft.jsch.Session;
|
|
|
|
|
import com.kamco.cd.training.common.exception.CustomApiException;
|
|
|
|
|
@@ -720,18 +719,26 @@ public class FIleChecker {
|
|
|
|
|
public static void unzip(String fileName, String destDirectory) throws IOException {
|
|
|
|
|
String zipFilePath = destDirectory + File.separator + fileName;
|
|
|
|
|
|
|
|
|
|
log.info("fileName : {}", fileName);
|
|
|
|
|
log.info("destDirectory : {}", destDirectory);
|
|
|
|
|
log.info("zipFilePath : {}", zipFilePath);
|
|
|
|
|
// zip 이름으로 폴더 생성 (확장자 제거)
|
|
|
|
|
String folderName =
|
|
|
|
|
fileName.endsWith(".zip") ? fileName.substring(0, fileName.length() - 4) : fileName;
|
|
|
|
|
log.info("folderName : {}", folderName);
|
|
|
|
|
|
|
|
|
|
File destDir = new File(destDirectory, folderName);
|
|
|
|
|
log.info("destDir : {}", destDir);
|
|
|
|
|
|
|
|
|
|
// 동일 폴더가 이미 있으면 삭제
|
|
|
|
|
log.info("111 destDir.exists() : {}", destDir.exists());
|
|
|
|
|
if (destDir.exists()) {
|
|
|
|
|
deleteDirectoryRecursively(destDir.toPath());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("222 destDir.exists() : {}", destDir.exists());
|
|
|
|
|
if (!destDir.exists()) {
|
|
|
|
|
log.info("mkdirs : {}", destDir.exists());
|
|
|
|
|
destDir.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -787,92 +794,6 @@ public class FIleChecker {
|
|
|
|
|
return destFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void uploadTo86(Path localFile) {
|
|
|
|
|
|
|
|
|
|
String host = "192.168.2.86";
|
|
|
|
|
int port = 22;
|
|
|
|
|
String username = "kcomu";
|
|
|
|
|
String password = "Kamco2025!";
|
|
|
|
|
|
|
|
|
|
String remoteDir = "/home/kcomu/data/request";
|
|
|
|
|
|
|
|
|
|
Session session = null;
|
|
|
|
|
ChannelSftp channel = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
JSch jsch = new JSch();
|
|
|
|
|
|
|
|
|
|
session = jsch.getSession(username, host, port);
|
|
|
|
|
session.setPassword(password);
|
|
|
|
|
|
|
|
|
|
Properties config = new Properties();
|
|
|
|
|
config.put("StrictHostKeyChecking", "no");
|
|
|
|
|
session.setConfig(config);
|
|
|
|
|
|
|
|
|
|
session.connect(10_000);
|
|
|
|
|
|
|
|
|
|
channel = (ChannelSftp) session.openChannel("sftp");
|
|
|
|
|
channel.connect(10_000);
|
|
|
|
|
|
|
|
|
|
// 목적지 디렉토리 이동
|
|
|
|
|
channel.cd(remoteDir);
|
|
|
|
|
|
|
|
|
|
// 업로드
|
|
|
|
|
channel.put(localFile.toString(), localFile.getFileName().toString());
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException("SFTP upload failed", e);
|
|
|
|
|
} finally {
|
|
|
|
|
if (channel != null) channel.disconnect();
|
|
|
|
|
if (session != null) session.disconnect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void unzipOn86Server(String zipPath, String targetDir) {
|
|
|
|
|
|
|
|
|
|
String host = "192.168.2.86";
|
|
|
|
|
String user = "kcomu";
|
|
|
|
|
String password = "Kamco2025!";
|
|
|
|
|
|
|
|
|
|
Session session = null;
|
|
|
|
|
ChannelExec channel = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
JSch jsch = new JSch();
|
|
|
|
|
|
|
|
|
|
session = jsch.getSession(user, host, 22);
|
|
|
|
|
session.setPassword(password);
|
|
|
|
|
|
|
|
|
|
Properties config = new Properties();
|
|
|
|
|
config.put("StrictHostKeyChecking", "no");
|
|
|
|
|
session.setConfig(config);
|
|
|
|
|
|
|
|
|
|
session.connect(10_000);
|
|
|
|
|
|
|
|
|
|
String command = "unzip -o " + zipPath + " -d " + targetDir;
|
|
|
|
|
|
|
|
|
|
channel = (ChannelExec) session.openChannel("exec");
|
|
|
|
|
channel.setCommand(command);
|
|
|
|
|
channel.setErrStream(System.err);
|
|
|
|
|
|
|
|
|
|
InputStream in = channel.getInputStream();
|
|
|
|
|
channel.connect();
|
|
|
|
|
|
|
|
|
|
// 출력 읽기(선택)
|
|
|
|
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
|
|
|
|
|
while (br.readLine() != null) {
|
|
|
|
|
// 필요하면 로그
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
} finally {
|
|
|
|
|
if (channel != null) channel.disconnect();
|
|
|
|
|
if (session != null) session.disconnect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<String> execCommandAndReadLines(String command) {
|
|
|
|
|
|
|
|
|
|
List<String> result = new ArrayList<>();
|
|
|
|
|
|