From 8995a87dc1599e2cbbfc7bc4ef0a8f68a159b5e5 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期日, 28 九月 2025 16:38:58 +0800
Subject: [PATCH] 优化
---
server/system_service/src/main/java/com/doumee/core/utils/FtpUtil.java | 39 ++++++++++++++++++++++++++++++++++++++-
1 files changed, 38 insertions(+), 1 deletions(-)
diff --git a/server/system_service/src/main/java/com/doumee/core/utils/FtpUtil.java b/server/system_service/src/main/java/com/doumee/core/utils/FtpUtil.java
index 8712f61..9c009bb 100644
--- a/server/system_service/src/main/java/com/doumee/core/utils/FtpUtil.java
+++ b/server/system_service/src/main/java/com/doumee/core/utils/FtpUtil.java
@@ -1,6 +1,8 @@
package com.doumee.core.utils;
import java.io.*;
+import java.net.MalformedURLException;
+import java.util.Date;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
@@ -50,6 +52,37 @@
FtpUtil.password =password;
connect();
}
+ /**
+ * 鍒濆鍖杅tp鏈嶅姟鍣�
+ */
+ public boolean connect() {
+ boolean flag = false;
+ try {
+ System.out.println("connecting...ftp鏈嶅姟鍣�:"+this.hostname+":"+this.port);
+ ftpClient.setRemoteVerificationEnabled(false);
+ ftpClient.connect(hostname, port); //杩炴帴ftp鏈嶅姟鍣�
+ ftpClient.login(username, password); //鐧诲綍ftp鏈嶅姟鍣�
+// if (FTPReply.isPositiveCompletion(ftpClient.sendCommand("OPTS UTF8", "ON"))) {
+// LOCAL_CHARSET = "UTF-8";
+// }
+ ftpClient.setControlEncoding("GBK");
+ ftpClient.enterLocalPassiveMode();
+ int replyCode = ftpClient.getReplyCode(); //鏄惁鎴愬姛鐧诲綍鏈嶅姟鍣�
+ if(!FTPReply.isPositiveCompletion(replyCode)){
+ log.error("connect failed...ftp鏈嶅姟鍣�:"+this.hostname+":"+this.port+"杩斿洖鐮侊細"+replyCode);
+ }else {
+ flag = true;
+ log.info("connect successful...ftp鏈嶅姟鍣�:"+this.hostname+":"+this.port+"杩斿洖鐮侊細"+replyCode);
+ }
+ }catch (MalformedURLException e) {
+ e.printStackTrace();
+ log.error("connect exception...ftp鏈嶅姟鍣�:"+this.hostname+":"+this.port+ e.getMessage());
+ }catch (IOException e) {
+ e.printStackTrace();
+ log.error("connect exception...ftp鏈嶅姟鍣�:"+this.hostname+":"+this.port+ e.getMessage());
+ }
+ return flag;
+ }
/** */
/**
@@ -59,7 +92,7 @@
* @return 鏄惁杩炴帴鎴愬姛
* @throws IOException
*/
- public boolean connect() throws IOException {
+ public boolean connect2() throws IOException {
ftpClient.connect(hostname, port);
ftpClient.setControlEncoding("GBK");
if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
@@ -236,6 +269,8 @@
}
public boolean uploadInputstream(InputStream inputStream, String remote) {
// 璁剧疆PassiveMode浼犺緭
+ Date d1 = new Date();
+ log.error("涓婁紶鏂囦欢鎴愬姛=============寮�濮�========="+DateUtil.getPlusTime2(d1));
try {
ftpClient.enterLocalPassiveMode();
// 璁剧疆浠ヤ簩杩涘埗娴佺殑鏂瑰紡浼犺緭
@@ -259,6 +294,8 @@
}else{
log.error("涓婁紶鏂囦欢澶辫触======================="+remote);
}
+ Date d2= new Date();
+ log.error("涓婁紶鏂囦欢鎴愬姛=============缁撴潫========="+DateUtil.getPlusTime2(d2) +"鑰楁椂姣锛�"+( (d2.getTime()-d1.getTime()) ));
return result;
}catch (Exception e){
e.printStackTrace();
--
Gitblit v1.9.3