From 9237e8e4d0a65f1976323294f258d456960ce20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A3=B4=E6=B5=A9=E5=AE=87?= <617594538@qq.com> Date: Thu, 21 Mar 2024 11:26:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20FTP=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/common/CommonController.java | 19 ------------------- .../src/main/resources/application-dev.yml | 11 +++++++++++ .../src/main/resources/application-nas.yml | 11 +++++++++++ .../src/main/resources/application-prod.yml | 11 +++++++++++ pnkx-admin/src/main/resources/application.yml | 2 +- .../constant/WebsiteAddressConstants.java | 2 +- .../java/com/pnkx/common/ftp/FtpTool.java | 18 +++++++++++------- 7 files changed, 46 insertions(+), 28 deletions(-) diff --git a/pnkx-admin/src/main/java/com/pnkx/web/controller/common/CommonController.java b/pnkx-admin/src/main/java/com/pnkx/web/controller/common/CommonController.java index 2f47923..808cf64 100644 --- a/pnkx-admin/src/main/java/com/pnkx/web/controller/common/CommonController.java +++ b/pnkx-admin/src/main/java/com/pnkx/web/controller/common/CommonController.java @@ -145,23 +145,4 @@ public class CommonController { log.error("下载文件失败", e); } } - - /** - * ftp获取单个文件 - */ - @GetMapping("/ftp/**") - public void getFtpFile(HttpServletRequest request, HttpServletResponse response) { - try { - // 下载文件并获取文件流 - InputStream fileStream = sysFileService.getFtpFile(request.getRequestURI().substring(4)); - // 设置响应头 - response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); - // 将文件流输出到响应 - IOUtils.copy(fileStream, response.getOutputStream()); - response.flushBuffer(); - } catch (IOException e) { - // 异常处理 - e.printStackTrace(); - } - } } diff --git a/pnkx-admin/src/main/resources/application-dev.yml b/pnkx-admin/src/main/resources/application-dev.yml index cc95394..06bd1ad 100644 --- a/pnkx-admin/src/main/resources/application-dev.yml +++ b/pnkx-admin/src/main/resources/application-dev.yml @@ -90,3 +90,14 @@ spring: wall: config: multi-statement-allow: true +ftp: + # ftp地址 + host: pnkx.cloud + # ftp端口 + port: 21 + # ftp用户名 + username: peihaoyu + # ftp密码 + password: Phy0316. + # ftp上传路径 + path: / diff --git a/pnkx-admin/src/main/resources/application-nas.yml b/pnkx-admin/src/main/resources/application-nas.yml index 04307ca..107a874 100644 --- a/pnkx-admin/src/main/resources/application-nas.yml +++ b/pnkx-admin/src/main/resources/application-nas.yml @@ -90,3 +90,14 @@ spring: wall: config: multi-statement-allow: true +ftp: + # ftp地址 + host: 192.168.31.104 + # ftp端口 + port: 21 + # ftp用户名 + username: peihaoyu + # ftp密码 + password: Phy0316. + # ftp上传路径 + path: / diff --git a/pnkx-admin/src/main/resources/application-prod.yml b/pnkx-admin/src/main/resources/application-prod.yml index c866ce8..a9b3bb1 100644 --- a/pnkx-admin/src/main/resources/application-prod.yml +++ b/pnkx-admin/src/main/resources/application-prod.yml @@ -90,3 +90,14 @@ spring: wall: config: multi-statement-allow: true +ftp: + # ftp地址 + host: pnkx.cloud + # ftp端口 + port: 21 + # ftp用户名 + username: peihaoyu + # ftp密码 + password: Phy0316. + # ftp上传路径 + path: / diff --git a/pnkx-admin/src/main/resources/application.yml b/pnkx-admin/src/main/resources/application.yml index f82948b..7f47d9b 100644 --- a/pnkx-admin/src/main/resources/application.yml +++ b/pnkx-admin/src/main/resources/application.yml @@ -41,7 +41,7 @@ spring: # 国际化资源文件路径 basename: i18n/messages profiles: - active: nas + active: dev # 文件上传 servlet: multipart: diff --git a/pnkx-common/src/main/java/com/pnkx/common/constant/WebsiteAddressConstants.java b/pnkx-common/src/main/java/com/pnkx/common/constant/WebsiteAddressConstants.java index af9437c..0f04814 100644 --- a/pnkx-common/src/main/java/com/pnkx/common/constant/WebsiteAddressConstants.java +++ b/pnkx-common/src/main/java/com/pnkx/common/constant/WebsiteAddressConstants.java @@ -14,5 +14,5 @@ public class WebsiteAddressConstants { public static final String WEB_SITE_ADDRESS = "https://pnkx.top/"; // FTP服务器地址 - public static final String FTP_SITE_ADDRESS = "https://pnkx.cloud:8866/"; + public static final String FTP_SITE_ADDRESS = "https://ftp.pnkx.top:8"; } diff --git a/pnkx-common/src/main/java/com/pnkx/common/ftp/FtpTool.java b/pnkx-common/src/main/java/com/pnkx/common/ftp/FtpTool.java index 380bb8b..eb7c62c 100644 --- a/pnkx-common/src/main/java/com/pnkx/common/ftp/FtpTool.java +++ b/pnkx-common/src/main/java/com/pnkx/common/ftp/FtpTool.java @@ -9,6 +9,7 @@ import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPReply; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; @@ -21,8 +22,6 @@ import java.util.Comparator; import java.util.List; import java.util.regex.Pattern; -import static cn.hutool.db.DbUtil.close; - /** * FtpConfig * @@ -44,23 +43,28 @@ public class FtpTool { /** * ftp 服务地址 */ - private static final String HOST = "pnkx.cloud"; + @Value("${ftp.host}") + private String HOST; /** * ftp 服务账户 */ - private static final String USER_NAME = "peihaoyu"; + @Value("${ftp.username}") + private String USER_NAME; /** * ftp 密码 */ - private static final String PWD = "Phy0316."; + @Value("${ftp.password}") + private String PWD; /** * 端口 ftp 默认 21 ,登录端口。20为传输端口,此处使用连接端口 */ - private static final Integer PORT = 21; + @Value("${ftp.port}") + private Integer PORT; /** * 目录 */ - private static final String PATH = "/"; + @Value("${ftp.path}") + private String PATH; /** * 创建连接