no message

main
이범준 4 months ago
parent 6eaf39691f
commit 603512e62c

@ -0,0 +1,15 @@
#!/bin/bash
#!/usr/bin/expect -f
if [ $# -lt 1]
then
echo "I Hope your input. [TARGET_FILE]"
exit
fi
TARGET_FILE=$1
SRC_DIR=$2
LAYOVER_DIR=$3
DEST_DIR=$4
DEST_NAME=$5
java -jar /gpta/source-app/cfs/relay_jar/customSender.jar $TARGET_FILE $SRC_DIR $LAYOVER_DIR $DEST_DIR $DEST_NAME &

@ -0,0 +1,82 @@
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
public class CustomSender {
public static final Logger logger = Logger.getLogger(CustomSender.class);
private static String wasWorkDir = "";
private static String webWorkDir = "";
private static String sujibWorkDir = "";
private static String finalDest = "";
private static String finalDestWorkDir = "";
public static void main(String[] args) {
String fileName = args[0];
wasWorkDir = args[1];
webWorkDir = args[2];
sujibWorkDir = args[3];
finalDestWorkDir = args[4];
finalDest = args[5];
CustomSender self = new CustomSender();
File file = new File(wasWorkDir + "/" + fileName);
int ftpResult = self.setFtpData(file, fileName);
if(ftpResult != -1) {
self.deliveryReq(
webWorkDir+"/"+file.getName(),
sujibWorkDir+"/"+file.getName(),
finalDestWorkDir+"/"+file.getName(),
finalDest
);
}
}
private void deliveryReq(String srcPath, String layoverPath, String destPath, String destName) {
FTPUtil ssh = new FTPUtil();
ssh.initExec("175.193.201.56", "tmax","tmax1234");
ssh.run("curl --insecure -X GET "
+ "d \"srcPath="+srcPath+"&layoverPath="+layoverPath+"&destPath="+destPath+"&from=web4&to="+destName+"\" "
+ "http://192.168.201.120/deliveryReq.do"
);
ssh.disconnectSession();
}
private int setFtpData(File file, String fileNm) {
FTPUtil sftp = new FTPUtil();
logger.debug("======== 업로드 시작 : " + fileNm);
sftp.init("175.193.201.56", "tmax","tmax1234");
Map<String, String> resultMap = new HashMap<String, String>();
resultMap.put("return", "0");
try {
sftp.upload3(webWorkDir+"/", file, resultMap);
} catch (Exception e) {
e.printStackTrace();
}
logger.debug("======== : " + resultMap.get("return"));
int nReturn = Integer.parseInt(resultMap.get("return"));
sftp.disconnect();
logger.debug("======== 업로드 끝 : " + nReturn);
return nReturn;
}
}

@ -8,6 +8,7 @@ import java.util.Map;
import org.apache.log4j.Logger;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
@ -19,6 +20,7 @@ public class FTPUtil {
private Session session = null;
private Channel channel = null;
private ChannelSftp channelSftp = null;
private ChannelExec channelExec = null;
private final Logger logger = Logger.getLogger(FTPUtil.class);
@ -63,6 +65,46 @@ public class FTPUtil {
System.out.println("==> Connected to " + host);
}
public void initExec(String host, String user, String password) {
System.out.println(host);
System.setProperty("java.net.preferIPv4Stack", "true");
System.out.println("==> Connecting to " + host);
// 1. JSch 객체를 생성한다.
JSch jsch = new JSch();
try {
// 2. 세션 객체를 생성한다(사용자 이름, 접속할 호스트, 포트를 인자로 전달한다.)
session = jsch.getSession(user, host, 10040);
// 3. 패스워드를 설정한다.
session.setPassword(password);
// 4. 세션과 관련된 정보를 설정한다.
java.util.Properties config = new java.util.Properties();
// 4-1. 호스트 정보를 검사하지 않는다.
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
System.out.println("======== 1: ");
// 5. 접속한다.
session.connect();
System.out.println("======== 2: ");
// 6. 실행 채널을 연다.
channel = session.openChannel("exec");
// 7. 채널에 연결한다.
channel.connect();
} catch (JSchException e) {
e.printStackTrace();
}
// 8. 채널을 실행용 채널 객체로 캐스팅한다.
channelExec = (ChannelExec) channel;
System.out.println("==> Connected to " + host);
}
public String mkdir2(String path) throws SftpException {
String[] pathArray = path.split("/");
@ -171,4 +213,16 @@ public class FTPUtil {
channelSftp.quit();
session.disconnect();
}
public void disconnectSession() {
session.disconnect();
}
public void run(String string) {
channelExec.setCommand(string);
try {
channelExec.connect();
} catch (JSchException e) {
e.printStackTrace();
}
channelExec.disconnect();
}
}

Loading…
Cancel
Save