From 6cdbd8f9cb636cfa43c26651f76b14ce81f16ef6 Mon Sep 17 00:00:00 2001 From: xusd <hugeinfo123> Date: Tue, 10 Sep 2024 10:17:55 +0800 Subject: [PATCH] ftp服务器修正 --- dyh-service/dyh-sys/src/main/java/cn/huge/module/file/utils/FtpUtils.java | 13 +++++++++++-- dyh-service/dyh-sys/src/main/resources/config/application-test.yml | 18 +++++++++++++++--- dyh-service/dyh-sys/src/main/java/cn/huge/module/file/controller/web/FileInfoWebController.java | 10 ++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/controller/web/FileInfoWebController.java b/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/controller/web/FileInfoWebController.java index 658fecd..d8987ec 100644 --- a/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/controller/web/FileInfoWebController.java +++ b/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/controller/web/FileInfoWebController.java @@ -309,6 +309,16 @@ } } + @DeleteMapping("/deleteFileById2") + public Object deleteFileById2(@RequestBody String id) { + try { + service.deleteFileById(id); + return ReturnSucUtils.getRepInfo(); + } catch (Exception e) { + return ReturnFailUtils.getRepInfo(); + } + } + /** * 根据多个所属编号查询附件并根据先根据ownerId再根据附件类型分组 * diff --git a/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/utils/FtpUtils.java b/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/utils/FtpUtils.java index 30c5e01..0b32bed 100644 --- a/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/utils/FtpUtils.java +++ b/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/utils/FtpUtils.java @@ -7,6 +7,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPClientConfig; +import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPReply; import org.springframework.stereotype.Component; @@ -117,10 +118,12 @@ clientConfig.setLenientFutureDates(true); ftpClient.configure(clientConfig); // 连接ftp + log.info("xsd host:{},{}",FtpFileConfig.getHostname(), FtpFileConfig.getPort()); ftpClient.connect(FtpFileConfig.getHostname(), FtpFileConfig.getPort()); if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { log.info("连接ftp成功!"); - ftpClient.login(FtpFileConfig.getUsername(), FtpFileConfig.getPassword()); + boolean login = ftpClient.login(FtpFileConfig.getUsername(), FtpFileConfig.getPassword()); + log.info("登录ftp成功:{}",login); if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { // 设置以二进制方式传输 ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); @@ -130,6 +133,7 @@ ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); // 设置缓冲区大小 ftpClient.setBufferSize(1024); + log.info("登录ftp成功!"); flag = true; } else { @@ -179,6 +183,8 @@ }else{ flag = true; } + FTPFile[] ftpFiles = ftpClient.listFiles(path); + log.info("xsd{}",ftpFiles); return flag; }catch (Exception e){ log.error("方法[FtpUtils.makeDir]调用异常:"+e, e); @@ -198,7 +204,10 @@ try { fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1"); log.info("上传文件名为:" + fileName); - ftpClient.storeFile(fileName, fileInputStream); + log.info("上传文件流:" + fileInputStream); + boolean b = ftpClient.storeFile(fileName, fileInputStream); + String status = ftpClient.getStatus(); + log.info("上传状态:{},{}" ,b, status); int reply = ftpClient.getReplyCode(); if (FTPReply.isPositiveCompletion(reply)) { flag = true; diff --git a/dyh-service/dyh-sys/src/main/resources/config/application-test.yml b/dyh-service/dyh-sys/src/main/resources/config/application-test.yml index 341d7ec..f546405 100644 --- a/dyh-service/dyh-sys/src/main/resources/config/application-test.yml +++ b/dyh-service/dyh-sys/src/main/resources/config/application-test.yml @@ -10,7 +10,7 @@ name: dyh-sys #数据源配置 datasource: - url: jdbc:dm://183.2.142.46:9006?schema=gzdyh_dev + url: jdbc:dm://183.2.142.46:9016?schema=gzdyh_dev username: SYSDBA password: SYSDBA driver-class-name: dm.jdbc.driver.DmDriver @@ -49,7 +49,7 @@ client: service-url: #注册中心单机 - defaultZone: http://localhost:9001/eureka + defaultZone: http://192.168.234.57:9001/eureka #注册中心集群 #defaultZone: http://localhost:8761/eureka,http://localhost:8762/eureka #是否注册到注册中心 @@ -95,7 +95,19 @@ ssl: enabled: false -#科大讯飞配置 +#ftp服务配置 +ftp: + #服务器ip地址 + hostname: 192.168.234.34 + #端口 + port: 21 + #用户名 + username: hugeinfo + #密码 + password: hugeinfo123 + #附件存储根目录 + rootdir: /deploy/ftp/gzdyh + xfyun: host_url: https://iat-api.xfyun.cn/v2/iat appid: 5c7b00be -- Gitblit v1.8.0