From bb48c066cc11f571be02eb0dc7f9ef26dd3151ca Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期三, 02 四月 2025 10:08:48 +0800
Subject: [PATCH] 代码初始化
---
server/system_service/src/main/java/com/doumee/core/utils/FtpUtil.java | 43 ++++++++++++++++++++++++++++++++++++++++---
1 files changed, 40 insertions(+), 3 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 5a6fbd5..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();
@@ -267,7 +304,7 @@
return false;
}
- public boolean uploadInputstreamBatch(InputStream inputStream, String remote, Boolean close) {
+ public boolean uploadInputstreamBatch(InputStream inputStream, String remote, Boolean close , Integer index ) {
// 璁剧疆PassiveMode浼犺緭
try {
ftpClient.enterLocalPassiveMode();
@@ -279,7 +316,7 @@
if (remote.contains("/")) {
remoteFileName = remote.substring(remote.lastIndexOf("/") + 1);
// 鍒涘缓鏈嶅姟鍣ㄨ繙绋嬬洰褰曠粨鏋勶紝鍒涘缓澶辫触鐩存帴杩斿洖
- if (StringUtils.equals(CreateDirecroty(remote, ftpClient), "2")) {
+ if (Constants.equalsInteger(index,Constants.ONE) && StringUtils.equals(CreateDirecroty(remote, ftpClient), "2")) {
log.error("鍒涘缓ftp鐩綍澶辫触======================="+remote);
return false;
}
--
Gitblit v1.9.3