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 | 77 +++++++++++++++++++++++++++++++++++++-
1 files changed, 75 insertions(+), 2 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 a62bf46..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;
@@ -15,6 +17,7 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
+import org.apache.xpath.operations.Bool;
import sun.misc.BASE64Encoder;
/** */
@@ -49,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;
+ }
/** */
/**
@@ -58,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())) {
@@ -235,9 +269,10 @@
}
public boolean uploadInputstream(InputStream inputStream, String remote) {
// 璁剧疆PassiveMode浼犺緭
+ Date d1 = new Date();
+ log.error("涓婁紶鏂囦欢鎴愬姛=============寮�濮�========="+DateUtil.getPlusTime2(d1));
try {
ftpClient.enterLocalPassiveMode();
-
// 璁剧疆浠ヤ簩杩涘埗娴佺殑鏂瑰紡浼犺緭
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.setControlEncoding("GBK");
@@ -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();
@@ -266,6 +303,42 @@
}
return false;
}
+
+ public boolean uploadInputstreamBatch(InputStream inputStream, String remote, Boolean close , Integer index ) {
+ // 璁剧疆PassiveMode浼犺緭
+ try {
+ ftpClient.enterLocalPassiveMode();
+ // 璁剧疆浠ヤ簩杩涘埗娴佺殑鏂瑰紡浼犺緭
+ ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
+ ftpClient.setControlEncoding("GBK");
+ // 瀵硅繙绋嬬洰褰曠殑澶勭悊
+ String remoteFileName = remote;
+ if (remote.contains("/")) {
+ remoteFileName = remote.substring(remote.lastIndexOf("/") + 1);
+ // 鍒涘缓鏈嶅姟鍣ㄨ繙绋嬬洰褰曠粨鏋勶紝鍒涘缓澶辫触鐩存帴杩斿洖
+ if (Constants.equalsInteger(index,Constants.ONE) && StringUtils.equals(CreateDirecroty(remote, ftpClient), "2")) {
+ log.error("鍒涘缓ftp鐩綍澶辫触======================="+remote);
+ return false;
+ }
+ }
+ boolean result = ftpClient.storeFile(remoteFileName, inputStream);
+ inputStream.close();
+ if(close){
+ ftpClient.logout();
+ }
+ if(result){
+ log.info("涓婁紶鏂囦欢鎴愬姛======================"+remote);
+ }else{
+ log.error("涓婁紶鏂囦欢澶辫触======================="+remote);
+ }
+ return result;
+ }catch (Exception e){
+ e.printStackTrace();
+ log.error("涓婁紶鏂囦欢澶辫触======================="+remote);
+ }
+ return false;
+ }
+
public int getNumFromStr(String str,char searchstr) {
int count = 0;
char[] charArray = str.toCharArray();
--
Gitblit v1.9.3