From 09cdc32bf8cd05ed62f39eea5e7e735075023e69 Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Tue, 22 Nov 2022 17:04:20 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=8E=92=E9=99=A4=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- src/test/java/baseTest/BaseTest.java | 39 ---------------------------- 2 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 src/test/java/baseTest/BaseTest.java diff --git a/.gitignore b/.gitignore index cc07bbd..3fd8530 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ log *.ipa *.apk .idea/ -.gitignore +#.gitignore !.gitignore # Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties` # should NOT be excluded as they contain compiler settings and other important diff --git a/src/test/java/baseTest/BaseTest.java b/src/test/java/baseTest/BaseTest.java deleted file mode 100644 index b6b9a33..0000000 --- a/src/test/java/baseTest/BaseTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package baseTest; - -import cn.hutool.core.lang.Console; -import org.junit.Before; -import org.junit.Test; -import weaver.conn.RecordSet; -import weaver.general.GCONST; - -/** - * @author EBU7-dev1-ayh - * create 2021/12/13 0013 23:08 - */ - - -public class BaseTest { - @Before - public void before() { - GCONST.setServerName("ecology"); - GCONST.setRootPath("F:\\wxr\\e9-project-ebu7-dev1\\src\\main\\resources\\"); - GCONST.setSystemFilePath("F:\\wxr\\e9-project-ebu7-dev1\\src\\main\\resources\\file"); -// GCONST.setLogPath("/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/log"); - } - - @Test - public void with() { - String sql = "select COMPANYNAME,LICENSE,EXPIREDATE,CVERSION from license "; - RecordSet rs = new RecordSet(); - rs.executeQuery(sql); - if (rs.next()) { - System.out.println("公司名称:" + rs.getString(1)); - System.out.println("LICENSE:" + rs.getString(2)); - System.out.println("授权到期日期:" + rs.getString(3)); - System.out.println("版本:" + rs.getString(4)); - Console.log(sql); - System.out.println(GCONST.getSysFilePath()); - // 打印文件位置 - } - } -} From 25db7d1f557fcabd5d926becf3240a800816e7a5 Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Tue, 22 Nov 2022 17:54:34 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=B5=8B=E8=AF=95sftp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hrorganization/sftp/FetchDataUtil.java | 26 +++++++++++-------- .../java/youhong/ai/pcn/TestOrganization.java | 4 ++- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java b/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java index 0a99315..5b4ee07 100644 --- a/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java +++ b/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java @@ -2,12 +2,11 @@ package weaver.youhong.ai.pcn.hrorganization.sftp; import aiyh.utils.excention.CustomerException; import aiyh.utils.fileUtil.sftp.SftpConnectUtil; +import cn.hutool.core.io.IoUtil; import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.SftpException; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; +import java.io.*; import java.util.Vector; /** @@ -36,20 +35,25 @@ public class FetchDataUtil { public void downloadFile(SftpConnectUtil sftpConnectUtil,String fileName, String targetFile){ try { - sftpConnectUtil.cd("/"); - Vector ls = sftpConnectUtil.ls("/"); - for (ChannelSftp.LsEntry l : ls) { - System.out.println(l.getFilename()); - } - + sftpConnectUtil.lcd("."); + // Vector ls = sftpConnectUtil.ls("."); + // for (Object l : ls) { + // System.out.println(l); + // } + // File file = new File(targetFile); if (!file.exists()) { file.getParentFile().mkdirs(); } - sftpConnectUtil.get(fileName + "/", new FileOutputStream(file)); - } catch (SftpException | FileNotFoundException e) { + sftpConnectUtil.get(fileName,new FileOutputStream(targetFile)); + + + } catch (SftpException e) { + sftpConnectUtil.close(); e.printStackTrace(); // throw new CustomerException("下载文件出错,down file error!"); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); } } diff --git a/src/test/java/youhong/ai/pcn/TestOrganization.java b/src/test/java/youhong/ai/pcn/TestOrganization.java index 6217afa..68246c2 100644 --- a/src/test/java/youhong/ai/pcn/TestOrganization.java +++ b/src/test/java/youhong/ai/pcn/TestOrganization.java @@ -2,6 +2,7 @@ package youhong.ai.pcn; import aiyh.utils.fileUtil.sftp.SftpConnectUtil; import baseTest.BaseTest; +import com.api.doc.detail.util.SFTPUtils; import org.junit.Test; import weaver.general.GCONST; import weaver.youhong.ai.pcn.hrorganization.sftp.FetchDataUtil; @@ -22,8 +23,9 @@ public class TestOrganization extends BaseTest { SftpConnectUtil sftpConnectUtil = new SftpConnectUtil( "HR Digital_PROD", "/Users/aoey.oct.22/company/Fan_wei/ssl/pcn/HR_Digital_PROD.pem",null,"222.73.197.242", - null,1000 * 10 + null,1000 * 100 ); + SFTPUtils sftpUtils = new SFTPUtils(); FetchDataUtil fetchDataUtil = new FetchDataUtil(); fetchDataUtil.downloadFile(sftpConnectUtil, "HRIS_DepartmentExport20200503", GCONST.getSysFilePath() + "HRIS_DepartmentExport20200503.csv"); From 2c0300f8d46098cc84d94774524d499216327ee7 Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Tue, 22 Nov 2022 18:21:50 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8DCusBaseAction=E4=B8=AD?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E8=8E=B7=E5=8F=96=E6=98=8E=E7=BB=86id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/aiyh/utils/action/CusBaseAction.java | 7 ++++--- .../java/aiyh/utils/fileUtil/sftp/SftpConnectUtil.java | 5 +++-- .../youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java | 8 ++++---- src/test/java/youhong/ai/pcn/TestOrganization.java | 7 ++++--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/aiyh/utils/action/CusBaseAction.java b/src/main/java/aiyh/utils/action/CusBaseAction.java index 6dc2c26..0eea3d6 100644 --- a/src/main/java/aiyh/utils/action/CusBaseAction.java +++ b/src/main/java/aiyh/utils/action/CusBaseAction.java @@ -192,7 +192,7 @@ public abstract class CusBaseAction implements Action { if (null == propertyArr) { return Collections.emptyMap(); } - Map mainTable = new HashMap<>((int) Math.ceil(propertyArr.length * 0.75)); + Map mainTable = new HashMap<>((int) Math.ceil(propertyArr.length * 1.4)); for (Property property : propertyArr) { String fieldName = property.getName(); String value = property.getValue(); @@ -209,7 +209,7 @@ public abstract class CusBaseAction implements Action { */ protected Map>> getDetailTableValue() { DetailTable[] detailTableArr = requestInfo.getDetailTableInfo().getDetailTable(); - Map>> detailDataList = new HashMap<>((int) Math.ceil(detailTableArr.length * 0.75)); + Map>> detailDataList = new HashMap<>((int) Math.ceil(detailTableArr.length * 1.4)); for (DetailTable detailTable : detailTableArr) { List> detailData = getDetailValue(detailTable); detailDataList.put(detailTable.getId(), detailData); @@ -242,7 +242,8 @@ public abstract class CusBaseAction implements Action { List> detailData = new ArrayList<>(rowArr.length); for (Row row : rowArr) { Cell[] cellArr = row.getCell(); - Map rowData = new HashMap<>((int) Math.ceil(cellArr.length * 0.75)); + Map rowData = new HashMap<>((int) Math.ceil(cellArr.length * (1 + 0.4))); + rowData.put("id",row.getId()); for (Cell cell : cellArr) { String fieldName = cell.getName(); String value = cell.getValue(); diff --git a/src/main/java/aiyh/utils/fileUtil/sftp/SftpConnectUtil.java b/src/main/java/aiyh/utils/fileUtil/sftp/SftpConnectUtil.java index 61c5d3b..7af9199 100644 --- a/src/main/java/aiyh/utils/fileUtil/sftp/SftpConnectUtil.java +++ b/src/main/java/aiyh/utils/fileUtil/sftp/SftpConnectUtil.java @@ -71,7 +71,7 @@ public class SftpConnectUtil extends ChannelSftp { this.port = port; this.password = password; this.sftpTimeOut = sftpTimeOut; - this.login(); + // this.login(); } @@ -81,7 +81,7 @@ public class SftpConnectUtil extends ChannelSftp { * @author youHong.ai */ - private void login() { + public ChannelSftp login() { JSch jSch = new JSch(); try { @@ -108,6 +108,7 @@ public class SftpConnectUtil extends ChannelSftp { channel.connect(); this.sftp = (ChannelSftp) channel; this.success = true; + return sftp; } catch (JSchException e) { throw new CustomerException("SFTP链接失败!", e); } diff --git a/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java b/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java index 5b4ee07..b7a9e48 100644 --- a/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java +++ b/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java @@ -32,10 +32,10 @@ public class FetchDataUtil { - public void downloadFile(SftpConnectUtil sftpConnectUtil,String fileName, - String targetFile){ + public void downloadFile(ChannelSftp sftp,SftpConnectUtil sftpConnectUtil, + String fileName, String targetFile){ try { - sftpConnectUtil.lcd("."); + // sftpConnectUtil.lcd("."); // Vector ls = sftpConnectUtil.ls("."); // for (Object l : ls) { // System.out.println(l); @@ -45,7 +45,7 @@ public class FetchDataUtil { if (!file.exists()) { file.getParentFile().mkdirs(); } - sftpConnectUtil.get(fileName,new FileOutputStream(targetFile)); + sftp.get(fileName,new FileOutputStream(targetFile)); } catch (SftpException e) { diff --git a/src/test/java/youhong/ai/pcn/TestOrganization.java b/src/test/java/youhong/ai/pcn/TestOrganization.java index 68246c2..48ff058 100644 --- a/src/test/java/youhong/ai/pcn/TestOrganization.java +++ b/src/test/java/youhong/ai/pcn/TestOrganization.java @@ -3,6 +3,7 @@ package youhong.ai.pcn; import aiyh.utils.fileUtil.sftp.SftpConnectUtil; import baseTest.BaseTest; import com.api.doc.detail.util.SFTPUtils; +import com.jcraft.jsch.ChannelSftp; import org.junit.Test; import weaver.general.GCONST; import weaver.youhong.ai.pcn.hrorganization.sftp.FetchDataUtil; @@ -25,9 +26,9 @@ public class TestOrganization extends BaseTest { "/Users/aoey.oct.22/company/Fan_wei/ssl/pcn/HR_Digital_PROD.pem",null,"222.73.197.242", null,1000 * 100 ); - SFTPUtils sftpUtils = new SFTPUtils(); + ChannelSftp login = sftpConnectUtil.login(); FetchDataUtil fetchDataUtil = new FetchDataUtil(); - fetchDataUtil.downloadFile(sftpConnectUtil, - "HRIS_DepartmentExport20200503", GCONST.getSysFilePath() + "HRIS_DepartmentExport20200503.csv"); + fetchDataUtil.downloadFile(login, sftpConnectUtil, + "HRIS_PositionExport20221120", GCONST.getSysFilePath() + "HRIS_PositionExport20221120.csv"); } } From 222e998b6c4bb0e745223f8866eb4d2398376461 Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Tue, 22 Nov 2022 18:48:25 +0800 Subject: [PATCH 4/4] =?UTF-8?q?sftp=E5=B7=A5=E5=85=B7=E7=B1=BB=E7=BC=96?= =?UTF-8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/fileUtil/sftp/SftpConnectUtil.java | 141 ----- .../youhong/ai/sftp/SftpConnectUtil.java | 571 ++++++++++++++++++ .../hrorganization/sftp/FetchDataUtil.java | 9 +- .../java/youhong/ai/pcn/TestOrganization.java | 6 +- 4 files changed, 576 insertions(+), 151 deletions(-) delete mode 100644 src/main/java/aiyh/utils/fileUtil/sftp/SftpConnectUtil.java create mode 100644 src/main/java/ebu7common/youhong/ai/sftp/SftpConnectUtil.java diff --git a/src/main/java/aiyh/utils/fileUtil/sftp/SftpConnectUtil.java b/src/main/java/aiyh/utils/fileUtil/sftp/SftpConnectUtil.java deleted file mode 100644 index 7af9199..0000000 --- a/src/main/java/aiyh/utils/fileUtil/sftp/SftpConnectUtil.java +++ /dev/null @@ -1,141 +0,0 @@ -package aiyh.utils.fileUtil.sftp; - -import aiyh.utils.excention.CustomerException; -import com.jcraft.jsch.*; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.util.Properties; - -/** - *

sftp连接工具类

- * - *

create: 2022-11-22 11:00

- * - * @author youHong.ai - */ - -@Getter -@NoArgsConstructor -public class SftpConnectUtil extends ChannelSftp { - - /** - * sftp对象 - */ - private ChannelSftp sftp; - /** - * 会话对象 - */ - private Session session; - /** - * 用户名 - */ - private String userName; - - /** - * 密码 - */ - private String password; - - /** - * 密钥地址 - */ - private String prvKeyFilePath; - - /** - * 是否成功 - */ - private boolean success; - - /** - * sftp地址 - */ - private String sftpIp; - - /** - * 端口 - */ - private Integer port; - - /** - * 超时事件 - */ - private Integer sftpTimeOut; - - - public SftpConnectUtil(String userName, String prvKeyFilePath,String password, String sftpIp, - Integer port, Integer sftpTimeOut) { - this.userName = userName; - this.prvKeyFilePath = prvKeyFilePath; - this.sftpIp = sftpIp; - this.port = port; - this.password = password; - this.sftpTimeOut = sftpTimeOut; - // this.login(); - } - - - /** - *

登陆sftp

- * - * @author youHong.ai - */ - - public ChannelSftp login() { - - JSch jSch = new JSch(); - try { - if (prvKeyFilePath != null && !"".equals(prvKeyFilePath)) { - if (password != null && !"".equals(password)) { - jSch.addIdentity(prvKeyFilePath, password); - } else { - jSch.addIdentity(prvKeyFilePath); - } - } else { - throw new RuntimeException("从sftp下载需要的ppk文件未找到"); - } - if (port != null && port > 0) { - this.session = jSch.getSession(userName, sftpIp, port); - } else { - this.session = jSch.getSession(userName, sftpIp); - } - Properties config = new Properties(); - config.put("StrictHostKeyChecking", "no"); - this.session.setConfig(config); - this.session.setTimeout(sftpTimeOut); - this.session.connect(); - Channel channel = this.session.openChannel("sftp"); - channel.connect(); - this.sftp = (ChannelSftp) channel; - this.success = true; - return sftp; - } catch (JSchException e) { - throw new CustomerException("SFTP链接失败!", e); - } - } - - /** - * 关闭连接 server - * - * @author youHong.ai - */ - private void logout() { - if (sftp != null) { - if (sftp.isConnected()) { - sftp.disconnect(); - } - } - if (session != null) { - if (session.isConnected()) { - session.disconnect(); - } - } - } - - /** - *

关闭链接释放资源

- */ - public void close(){ - this.login(); - } -} diff --git a/src/main/java/ebu7common/youhong/ai/sftp/SftpConnectUtil.java b/src/main/java/ebu7common/youhong/ai/sftp/SftpConnectUtil.java new file mode 100644 index 0000000..3395123 --- /dev/null +++ b/src/main/java/ebu7common/youhong/ai/sftp/SftpConnectUtil.java @@ -0,0 +1,571 @@ +package ebu7common.youhong.ai.sftp; + +import aiyh.utils.excention.CustomerException; +import com.jcraft.jsch.*; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Hashtable; +import java.util.Properties; +import java.util.Vector; + +/** + *

sftp连接工具类

+ * + *

create: 2022-11-22 11:00

+ * + * @author youHong.ai + */ + +@Getter +@NoArgsConstructor +public class SftpConnectUtil extends ChannelSftp { + + /** + * sftp对象 + */ + private ChannelSftp sftp; + /** + * 会话对象 + */ + private Session session; + /** + * 用户名 + */ + private String userName; + + /** + * 密码 + */ + private String password; + + /** + * 密钥地址 + */ + private String prvKeyFilePath; + + /** + * 是否成功 + */ + private boolean success; + + /** + * sftp地址 + */ + private String sftpIp; + + /** + * 端口 + */ + private Integer port; + + /** + * 超时事件 + */ + private Integer sftpTimeOut; + + + public SftpConnectUtil(String userName, String prvKeyFilePath,String password, String sftpIp, + Integer port, Integer sftpTimeOut) { + this.userName = userName; + this.prvKeyFilePath = prvKeyFilePath; + this.sftpIp = sftpIp; + this.port = port; + this.password = password; + this.sftpTimeOut = sftpTimeOut; + this.login(); + } + + + /** + *

登陆sftp

+ * + * @author youHong.ai + */ + + private void login() { + + JSch jSch = new JSch(); + try { + if (prvKeyFilePath != null && !"".equals(prvKeyFilePath)) { + if (password != null && !"".equals(password)) { + jSch.addIdentity(prvKeyFilePath, password); + } else { + jSch.addIdentity(prvKeyFilePath); + } + } else { + throw new RuntimeException("从sftp下载需要的ppk文件未找到"); + } + if (port != null && port > 0) { + this.session = jSch.getSession(userName, sftpIp, port); + } else { + this.session = jSch.getSession(userName, sftpIp); + } + Properties config = new Properties(); + config.put("StrictHostKeyChecking", "no"); + this.session.setConfig(config); + this.session.setTimeout(sftpTimeOut); + this.session.connect(); + Channel channel = this.session.openChannel("sftp"); + channel.connect(); + this.sftp = (ChannelSftp) channel; + this.success = true; + } catch (JSchException e) { + throw new CustomerException("SFTP链接失败!", e); + } + } + + /** + * 关闭连接 server + * + * @author youHong.ai + */ + private void logout() { + if (sftp != null) { + if (sftp.isConnected()) { + sftp.disconnect(); + } + } + if (session != null) { + if (session.isConnected()) { + session.disconnect(); + } + } + } + + /** + *

关闭链接释放资源

+ */ + public void close(){ + this.login(); + } + + @Override + public boolean isClosed() { + return this.sftp.isClosed(); + } + + @Override + public void setBulkRequests(int bulk_requests) throws JSchException { + this.sftp.setBulkRequests(bulk_requests); + } + + @Override + public int getBulkRequests() { + return this.sftp.getBulkRequests(); + } + + @Override + public void start() throws JSchException { + this.sftp.start(); + } + + @Override + public boolean isEOF() { + return this.sftp.isEOF(); + } + + @Override + public void setInputStream(InputStream in) { + this.sftp.setInputStream(in); + } + + @Override + public void setInputStream(InputStream in, boolean dontclose) { + this.sftp.setInputStream(in, dontclose); + } + + @Override + public void setOutputStream(OutputStream out) { + this.sftp.setOutputStream(out); + } + + @Override + public void setOutputStream(OutputStream out, boolean dontclose) { + this.sftp.setOutputStream(out, dontclose); + } + + @Override + public void setExtOutputStream(OutputStream out) { + this.sftp.setExtOutputStream(out); + } + + @Override + public void setExtOutputStream(OutputStream out, boolean dontclose) { + this.sftp.setExtOutputStream(out, dontclose); + } + + @Override + public InputStream getInputStream() throws IOException { + return this.sftp.getInputStream(); + } + + @Override + public InputStream getExtInputStream() throws IOException { + return this.sftp.getExtInputStream(); + } + + @Override + public OutputStream getOutputStream() throws IOException { + return this.sftp.getOutputStream(); + } + + @Override + public void quit() { + this.sftp.quit(); + } + + @Override + public void exit() { + this.sftp.exit(); + } + + @Override + public void lcd(String path) throws SftpException { + this.sftp.lcd(path); + } + + @Override + public void cd(String path) throws SftpException { + this.sftp.cd(path); + } + + @Override + public void put(String src, String dst) throws SftpException { + this.sftp.put(src, dst); + } + + @Override + public void put(String src, String dst, int mode) throws SftpException { + this.sftp.put(src, dst, mode); + } + + @Override + public void put(String src, String dst, SftpProgressMonitor monitor) throws SftpException { + this.sftp.put(src, dst, monitor); + } + + @Override + public void put(String src, String dst, SftpProgressMonitor monitor, int mode) throws SftpException { + this.sftp.put(src, dst, monitor, mode); + } + + @Override + public void put(InputStream src, String dst) throws SftpException { + this.sftp.put(src, dst); + } + + @Override + public void put(InputStream src, String dst, int mode) throws SftpException { + this.sftp.put(src, dst, mode); + } + + @Override + public void put(InputStream src, String dst, SftpProgressMonitor monitor) throws SftpException { + this.sftp.put(src, dst, monitor); + } + + @Override + public void put(InputStream src, String dst, SftpProgressMonitor monitor, int mode) throws SftpException { + this.sftp.put(src, dst, monitor, mode); + } + + @Override + public void _put(InputStream src, String dst, SftpProgressMonitor monitor, int mode) throws SftpException { + this.sftp._put(src, dst, monitor, mode); + } + + @Override + public OutputStream put(String dst) throws SftpException { + return this.sftp.put(dst); + } + + @Override + public OutputStream put(String dst, int mode) throws SftpException { + return this.sftp.put(dst, mode); + } + + @Override + public OutputStream put(String dst, SftpProgressMonitor monitor, int mode) throws SftpException { + return this.sftp.put(dst, monitor, mode); + } + + @Override + public OutputStream put(String dst, SftpProgressMonitor monitor, int mode, long offset) throws SftpException { + return this.sftp.put(dst, monitor, mode, offset); + } + + @Override + public void get(String src, String dst) throws SftpException { + this.sftp.get(src, dst); + } + + @Override + public void get(String src, String dst, SftpProgressMonitor monitor) throws SftpException { + this.sftp.get(src, dst, monitor); + } + + @Override + public void get(String src, String dst, SftpProgressMonitor monitor, int mode) throws SftpException { + this.sftp.get(src, dst, monitor, mode); + } + + @Override + public void get(String src, OutputStream dst) throws SftpException { + this.sftp.get(src, dst); + } + + @Override + public void get(String src, OutputStream dst, SftpProgressMonitor monitor) throws SftpException { + this.sftp.get(src, dst, monitor); + } + + @Override + public void get(String src, OutputStream dst, SftpProgressMonitor monitor, int mode, long skip) throws SftpException { + this.sftp.get(src, dst, monitor, mode, skip); + } + + @Override + public InputStream get(String src) throws SftpException { + return this.sftp.get(src); + } + + @Override + public InputStream get(String src, SftpProgressMonitor monitor) throws SftpException { + return this.sftp.get(src, monitor); + } + + @Override + public InputStream get(String src, int mode) throws SftpException { + return this.sftp.get(src, mode); + } + + @Override + public InputStream get(String src, SftpProgressMonitor monitor, int mode) throws SftpException { + return this.sftp.get(src, monitor, mode); + } + + @Override + public InputStream get(String src, SftpProgressMonitor monitor, long skip) throws SftpException { + return this.sftp.get(src, monitor, skip); + } + + @Override + public Vector ls(String path) throws SftpException { + return this.sftp.ls(path); + } + + @Override + public void ls(String path, LsEntrySelector selector) throws SftpException { + this.sftp.ls(path, selector); + } + + @Override + public String readlink(String path) throws SftpException { + return this.sftp.readlink(path); + } + + @Override + public void symlink(String oldpath, String newpath) throws SftpException { + this.sftp.symlink(oldpath, newpath); + } + + @Override + public void hardlink(String oldpath, String newpath) throws SftpException { + this.sftp.hardlink(oldpath, newpath); + } + + @Override + public void rename(String oldpath, String newpath) throws SftpException { + this.sftp.rename(oldpath, newpath); + } + + @Override + public void rm(String path) throws SftpException { + this.sftp.rm(path); + } + + @Override + public void chgrp(int gid, String path) throws SftpException { + this.sftp.chgrp(gid, path); + } + + @Override + public void chown(int uid, String path) throws SftpException { + this.sftp.chown(uid, path); + } + + @Override + public void chmod(int permissions, String path) throws SftpException { + this.sftp.chmod(permissions, path); + } + + @Override + public void setMtime(String path, int mtime) throws SftpException { + this.sftp.setMtime(path, mtime); + } + + @Override + public void rmdir(String path) throws SftpException { + this.sftp.rmdir(path); + } + + @Override + public void mkdir(String path) throws SftpException { + this.sftp.mkdir(path); + } + + @Override + public SftpATTRS stat(String path) throws SftpException { + return this.sftp.stat(path); + } + + @Override + public SftpStatVFS statVFS(String path) throws SftpException { + return this.sftp.statVFS(path); + } + + @Override + public SftpATTRS lstat(String path) throws SftpException { + return this.sftp.lstat(path); + } + + @Override + public void setStat(String path, SftpATTRS attr) throws SftpException { + this.sftp.setStat(path, attr); + } + + @Override + public String pwd() throws SftpException { + return this.sftp.pwd(); + } + + @Override + public String lpwd() { + return this.sftp.lpwd(); + } + + @Override + public String version() { + return this.sftp.version(); + } + + @Override + public String getHome() throws SftpException { + return this.sftp.getHome(); + } + + @Override + public void disconnect() { + this.sftp.disconnect(); + } + + @Override + public boolean isConnected() { + return this.sftp.isConnected(); + } + + @Override + public void sendSignal(String signal) throws Exception { + this.sftp.sendSignal(signal); + } + + @Override + public int getExitStatus() { + return this.sftp.getExitStatus(); + } + + @Override + public int getId() { + return this.sftp.getId(); + } + + @Override + public int getServerVersion() throws SftpException { + return this.sftp.getServerVersion(); + } + + @Override + public void setFilenameEncoding(String encoding) throws SftpException { + this.sftp.setFilenameEncoding(encoding); + } + + @Override + public String getExtension(String key) { + return this.sftp.getExtension(key); + } + + @Override + public String realpath(String path) throws SftpException { + return this.sftp.realpath(path); + } + + @Override + public void setAgentForwarding(boolean enable) { + this.sftp.setAgentForwarding(enable); + } + + @Override + public void connect() throws JSchException { + this.sftp.connect(); + } + + @Override + public void connect(int connectTimeout) throws JSchException { + this.sftp.connect(connectTimeout); + } + + @Override + public void setXForwarding(boolean enable) { + this.sftp.setXForwarding(enable); + } + + @Override + public void setEnv(Hashtable env) { + this.sftp.setEnv(env); + } + + @Override + public void setEnv(String name, String value) { + this.sftp.setEnv(name, value); + } + + @Override + public void setEnv(byte[] name, byte[] value) { + this.sftp.setEnv(name, value); + } + + @Override + public void setPty(boolean enable) { + this.sftp.setPty(enable); + } + + @Override + public void setTerminalMode(byte[] terminal_mode) { + this.sftp.setTerminalMode(terminal_mode); + } + + @Override + public void setPtySize(int col, int row, int wp, int hp) { + this.sftp.setPtySize(col, row, wp, hp); + } + + @Override + public void setPtyType(String ttype) { + this.sftp.setPtyType(ttype); + } + + @Override + public void setPtyType(String ttype, int col, int row, int wp, int hp) { + this.sftp.setPtyType(ttype, col, row, wp, hp); + } + + + @Override + public void run() { + this.sftp.run(); + } +} diff --git a/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java b/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java index b7a9e48..713f78e 100644 --- a/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java +++ b/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java @@ -1,13 +1,10 @@ package weaver.youhong.ai.pcn.hrorganization.sftp; -import aiyh.utils.excention.CustomerException; -import aiyh.utils.fileUtil.sftp.SftpConnectUtil; -import cn.hutool.core.io.IoUtil; +import ebu7common.youhong.ai.sftp.SftpConnectUtil; import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.SftpException; import java.io.*; -import java.util.Vector; /** *

获取数据工具

@@ -32,7 +29,7 @@ public class FetchDataUtil { - public void downloadFile(ChannelSftp sftp,SftpConnectUtil sftpConnectUtil, + public void downloadFile(SftpConnectUtil sftpConnectUtil, String fileName, String targetFile){ try { // sftpConnectUtil.lcd("."); @@ -45,7 +42,7 @@ public class FetchDataUtil { if (!file.exists()) { file.getParentFile().mkdirs(); } - sftp.get(fileName,new FileOutputStream(targetFile)); + sftpConnectUtil.get(fileName,new FileOutputStream(targetFile)); } catch (SftpException e) { diff --git a/src/test/java/youhong/ai/pcn/TestOrganization.java b/src/test/java/youhong/ai/pcn/TestOrganization.java index 48ff058..21963cd 100644 --- a/src/test/java/youhong/ai/pcn/TestOrganization.java +++ b/src/test/java/youhong/ai/pcn/TestOrganization.java @@ -1,8 +1,7 @@ package youhong.ai.pcn; -import aiyh.utils.fileUtil.sftp.SftpConnectUtil; +import ebu7common.youhong.ai.sftp.SftpConnectUtil; import baseTest.BaseTest; -import com.api.doc.detail.util.SFTPUtils; import com.jcraft.jsch.ChannelSftp; import org.junit.Test; import weaver.general.GCONST; @@ -26,9 +25,8 @@ public class TestOrganization extends BaseTest { "/Users/aoey.oct.22/company/Fan_wei/ssl/pcn/HR_Digital_PROD.pem",null,"222.73.197.242", null,1000 * 100 ); - ChannelSftp login = sftpConnectUtil.login(); FetchDataUtil fetchDataUtil = new FetchDataUtil(); - fetchDataUtil.downloadFile(login, sftpConnectUtil, + fetchDataUtil.downloadFile(sftpConnectUtil, "HRIS_PositionExport20221120", GCONST.getSysFilePath() + "HRIS_PositionExport20221120.csv"); } }