diff --git a/src/com/eactive/eai/batch/ftp/FTPUtil.java b/src/com/eactive/eai/batch/ftp/FTPUtil.java index 78846d3..29db6a4 100644 --- a/src/com/eactive/eai/batch/ftp/FTPUtil.java +++ b/src/com/eactive/eai/batch/ftp/FTPUtil.java @@ -20,31 +20,31 @@ public class FTPUtil { } // 20241008 sftp jsch 방식 list - public static FTPFileObject[] listFilesJSCH(String server, int port, String username, String password, String path, boolean isSftp, Logger logger, String authType) + public static FTPFileObject[] listFilesJSCH(String server, int port, String username, String password, String path, boolean isSftp, Logger logger, String authType, String proxyServer) throws IOException { if ( isSftp ){ - return SFTPAdaptor.listFilesJSCH(server, port, username, password, path, logger, authType); + return SFTPAdaptor.listFilesJSCH(server, port, username, password, path, logger, authType, proxyServer); }else{ return FTPAdaptor.listFiles2(server, port, username, password, path, logger); } } - public static long retrieve(BatchDoc batchDoc, String server, int port, String username, String password, String remote, String remoteFileName, String localPath, - int connTimeout, int setTimeout, boolean isSftp, int bandWidth, Logger logger, String authType) throws Exception { - - if ( isSftp ){ - return SFTPAdaptor.retrieveJSCH(batchDoc, server, port, username, password, remote, remoteFileName, localPath, connTimeout, setTimeout, bandWidth, logger, authType); - }else{ - return FTPAdaptor.retrieve(batchDoc,server, port, username, password, remote+remoteFileName, localPath, bandWidth, logger, ""); - } - } +// public static long retrieve(BatchDoc batchDoc, String server, int port, String username, String password, String remote, String remoteFileName, String localPath, +// int connTimeout, int setTimeout, boolean isSftp, int bandWidth, Logger logger, String authType) throws Exception { +// +// if ( isSftp ){ +// return SFTPAdaptor.retrieveJSCH(batchDoc, server, port, username, password, remote, remoteFileName, localPath, connTimeout, setTimeout, bandWidth, logger, authType); +// }else{ +// return FTPAdaptor.retrieve(batchDoc,server, port, username, password, remote+remoteFileName, localPath, bandWidth, logger, ""); +// } +// } public static long retrieve(BatchDoc batchDoc, String server, int port, String username, String password, String remote, String remoteFileName, String localPath, - int connTimeout, int setTimeout, int bandWidth, Logger logger, String authType, String fileType) throws Exception { + int connTimeout, int setTimeout, int bandWidth, Logger logger, String authType, String fileType, String proxyServer) throws Exception { if ( "0".equals(authType)) { return FTPAdaptor.retrieve(batchDoc,server, port, username, password, remote+remoteFileName, localPath, bandWidth, logger, fileType); }else { - return SFTPAdaptor.retrieveJSCH(batchDoc, server, port, username, password, remote, remoteFileName, localPath, connTimeout, setTimeout, bandWidth, logger, authType); + return SFTPAdaptor.retrieveJSCH(batchDoc, server, port, username, password, remote, remoteFileName, localPath, connTimeout, setTimeout, bandWidth, logger, authType, proxyServer); } } @@ -58,10 +58,10 @@ public class FTPUtil { } public static boolean store(BatchDoc batchDoc, String server, int port, String username, String password, String remote, String remoteFileName, String localPath, - int connTimeout, int setTimeout, boolean isSftp, int bandWidth, Logger logger, String authType) throws Exception { + int connTimeout, int setTimeout, boolean isSftp, int bandWidth, Logger logger, String authType, String proxyServer) throws Exception { if ( isSftp ){ - return SFTPAdaptor.storeJSCH(batchDoc, server, port, username, password, remote, remoteFileName, localPath, connTimeout, setTimeout, bandWidth, logger, authType); + return SFTPAdaptor.storeJSCH(batchDoc, server, port, username, password, remote, remoteFileName, localPath, connTimeout, setTimeout, bandWidth, logger, authType, proxyServer); }else{ return FTPAdaptor.store(batchDoc,server, port, username, password, remote+remoteFileName, localPath, bandWidth, logger); } diff --git a/src/com/eactive/eai/batch/ftp/SFTPAdaptor.java b/src/com/eactive/eai/batch/ftp/SFTPAdaptor.java index d646321..bb56c42 100644 --- a/src/com/eactive/eai/batch/ftp/SFTPAdaptor.java +++ b/src/com/eactive/eai/batch/ftp/SFTPAdaptor.java @@ -27,6 +27,7 @@ import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.ChannelSftp.LsEntry; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.ProxyHTTP; import com.jcraft.jsch.Session; import com.jcraft.jsch.SftpATTRS; import com.jcraft.jsch.SftpException; @@ -216,7 +217,8 @@ public class SFTPAdaptor { * @throws Exception */ protected static long retrieveJSCH(BatchDoc batchDoc, String server, int port, String username, - String password, String remote, String remoteFileName, String localPath, int connTimeout, int setTimeout, int bandWidthLimit, Logger logger, String authType) throws Exception { + String password, String remote, String remoteFileName, String localPath, int connTimeout, int setTimeout, + int bandWidthLimit, Logger logger, String authType, String proxyServer) throws Exception { logger.debug("[SFHT retrieve]remote-->" + remote); logger.debug("[SFHT retrieve]localPath-->" + localPath); @@ -239,6 +241,20 @@ public class SFTPAdaptor { if (!StringUtils.equals(authType, Transfer.AUTH_TYPE_KEY)) { session.setPassword(password); } + + if(proxyServer != null && !proxyServer.isEmpty()) {// 20251112 + try { + String[] parts = proxyServer.split(":"); + String proxyHost = parts[0]; + int proxyPort = (parts.length > 1) ? Integer.parseInt(parts[1]) : 8080; + + ProxyHTTP proxy = new ProxyHTTP(proxyHost, proxyPort); + session.setProxy(proxy); + }catch(Exception e) { + logger.error("Proxy set ERROR : "+e.getMessage()); + } + } + session.setConfig("StrictHostKeyChecking", "no"); session.setConfig("max_input_buffer_size","increased_size"); @@ -344,7 +360,8 @@ public class SFTPAdaptor { * @throws Exception */ protected static boolean storeJSCH(BatchDoc batchDoc, String server, int port, String username, - String password, String remote, String remoteFileName, String localFileName, int connTimeout, int setTimeout, int bandWidthLimit, Logger logger, String authType) throws Exception { + String password, String remote, String remoteFileName, String localFileName, int connTimeout, int setTimeout, + int bandWidthLimit, Logger logger, String authType, String proxyServer) throws Exception { logger.debug("[SFHT storeJSCH]remote-->" + remote); logger.debug("[SFHT storeJSCH]remoteFileName-->" + remoteFileName); @@ -371,6 +388,19 @@ public class SFTPAdaptor { if (!StringUtils.equals(authType, Transfer.AUTH_TYPE_KEY)) { session.setPassword(password); } + + if(proxyServer != null && !proxyServer.isEmpty()) { + try { + String[] parts = proxyServer.split(":"); + String proxyHost = parts[0]; + int proxyPort = (parts.length > 1) ? Integer.parseInt(parts[1]) : 8080; + + ProxyHTTP proxy = new ProxyHTTP(proxyHost, proxyPort); + session.setProxy(proxy); + }catch(Exception e) { + logger.error("Proxy set ERROR : "+e.getMessage()); + } + } session.setConfig("StrictHostKeyChecking", "no"); session.setConfig("max_input_buffer_size","increased_size"); @@ -1186,7 +1216,7 @@ public class SFTPAdaptor { - protected static FTPFileObject[] listFilesJSCH(String server, int port, String username, String password, String path, Logger logger, String authType) throws IOException { + protected static FTPFileObject[] listFilesJSCH(String server, int port, String username, String password, String path, Logger logger, String authType, String proxyServer) throws IOException { logger.debug("[SFHT connect]server -->" + server); logger.debug("[SFHT connect]port -->" + port); logger.debug("[SFHT connect]username-->" + username); @@ -1204,8 +1234,28 @@ public class SFTPAdaptor { //JSch.setLogger(new SFTPLogger()); - session = jsch.getSession(username, serverList[inx], port); - session.setPassword(password); + if (StringUtils.equals(authType, Transfer.AUTH_TYPE_ID)) { + session = jsch.getSession(username, serverList[inx], port); + session.setPassword(password); + // key 방식 인증 + } else if (StringUtils.equals(authType, Transfer.AUTH_TYPE_KEY)) { + jsch.addIdentity(password); + session = jsch.getSession(username, serverList[inx], port); + } + + if(proxyServer != null && !proxyServer.isEmpty()) {// 20251112 + try { + String[] parts = proxyServer.split(":"); + String proxyHost = parts[0]; + int proxyPort = (parts.length > 1) ? Integer.parseInt(parts[1]) : 8080; + + ProxyHTTP proxy = new ProxyHTTP(proxyHost, proxyPort); + session.setProxy(proxy); + }catch(Exception e) { + logger.error("Proxy set ERROR : "+e.getMessage()); + } + } + session.setConfig("StrictHostKeyChecking", "no"); session.setConfig("PreferredAuthentications","password"); session.setTimeout(300 * 1000);