From cc5d567bc58ce9657ce504fac6daa804ef9a15fa Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期五, 15 十二月 2023 10:29:08 +0800
Subject: [PATCH] 海康接口对接开发

---
 server/dmvisit_service/src/main/java/com/doumee/core/utils/FtpUtil.java |   48 ++++++++++++++++++++++++------------------------
 1 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/server/dmvisit_service/src/main/java/com/doumee/core/utils/FtpUtil.java b/server/dmvisit_service/src/main/java/com/doumee/core/utils/FtpUtil.java
index 9e2a26a..a62bf46 100644
--- a/server/dmvisit_service/src/main/java/com/doumee/core/utils/FtpUtil.java
+++ b/server/dmvisit_service/src/main/java/com/doumee/core/utils/FtpUtil.java
@@ -29,6 +29,10 @@
 @Slf4j
 public class FtpUtil {
 	public FTPClient ftpClient = new FTPClient();
+	public static String hostname;
+	public static int port;
+	public static String username;
+	public static  String password;
 
 	public FtpUtil() {
 		// 璁剧疆灏嗚繃绋嬩腑浣跨敤鍒扮殑鍛戒护杈撳嚭鍒版帶鍒跺彴
@@ -39,26 +43,22 @@
 	public FtpUtil(String hostname, int port, String username, String password)
 			throws IOException {
 		// 璁剧疆灏嗚繃绋嬩腑浣跨敤鍒扮殑鍛戒护杈撳嚭鍒版帶鍒跺彴
-		connect(hostname, port, username, password);
+		FtpUtil.hostname =hostname;
+		FtpUtil.port =port;
+		FtpUtil.username =username;
+		FtpUtil.password =password;
+		connect();
 	}
 
 	/** */
 	/**
 	 * 杩炴帴鍒癋TP鏈嶅姟鍣�
 	 *
-	 * @param hostname
-	 *            涓绘満鍚�
-	 * @param port
-	 *            绔彛
-	 * @param username
-	 *            鐢ㄦ埛鍚�
-	 * @param password
 	 *            瀵嗙爜
 	 * @return 鏄惁杩炴帴鎴愬姛
 	 * @throws IOException
 	 */
-	public boolean connect(String hostname, int port, String username,
-			String password) throws IOException {
+	public boolean connect() throws IOException {
 		ftpClient.connect(hostname, port);
 		ftpClient.setControlEncoding("GBK");
 		if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
@@ -243,8 +243,8 @@
 			ftpClient.setControlEncoding("GBK");
 			// 瀵硅繙绋嬬洰褰曠殑澶勭悊
 			String remoteFileName = remote;
-			if (remote.contains(File.separator)) {
-				remoteFileName = remote.substring(remote.lastIndexOf(File.separator) + 1);
+			if (remote.contains("/")) {
+				remoteFileName = remote.substring(remote.lastIndexOf("/") + 1);
 				// 鍒涘缓鏈嶅姟鍣ㄨ繙绋嬬洰褰曠粨鏋勶紝鍒涘缓澶辫触鐩存帴杩斿洖
 				if (StringUtils.equals(CreateDirecroty(remote, ftpClient), "2")) {
 					log.error("鍒涘缓ftp鐩綍澶辫触======================="+remote);
@@ -298,8 +298,8 @@
 		String result;
 		// 瀵硅繙绋嬬洰褰曠殑澶勭悊
 		String remoteFileName = remote ;
-		 if (remote.contains(File.separator)) {
-			remoteFileName = remote.substring(remote.lastIndexOf(File.separator) + 1);
+		 if (remote.contains("/")) {
+			remoteFileName = remote.substring(remote.lastIndexOf("/") + 1);
 			// 鍒涘缓鏈嶅姟鍣ㄨ繙绋嬬洰褰曠粨鏋勶紝鍒涘缓澶辫触鐩存帴杩斿洖
 			if (StringUtils.equals(CreateDirecroty(remote, ftpClient), "2")) {
 				return "2";
@@ -372,20 +372,20 @@
 			throws IOException {
 		String status = "1";
 		// UploadStatus status = UploadStatus.Create_Directory_Success;
-		String directory = remote.substring(0, remote.lastIndexOf(File.separator) + 1);
-		if (!directory.equalsIgnoreCase(File.separator)
+		String directory = remote.substring(0, remote.lastIndexOf("/") + 1);
+		if (!directory.equalsIgnoreCase("/")
 				&& !ftpClient.changeWorkingDirectory(new String(directory
 				.getBytes("GBK"), "iso-8859-1"))) {
 			// 濡傛灉杩滅▼鐩綍涓嶅瓨鍦紝鍒欓�掑綊鍒涘缓杩滅▼鏈嶅姟鍣ㄧ洰褰�
 			int start = 0;
 			int end = 0;
-			if (directory.startsWith(File.separator)) {
+			if (directory.startsWith("/")) {
 				start = 1;
 			} else {
 				start = 0;
 			}
 			end = directory
-					.indexOf(File.separator, start);
+					.indexOf("/", start);
 			while (true) {
 				String subDirectory = new String(remote.substring(start, end)
 						.getBytes("GBK"), "iso-8859-1");
@@ -400,7 +400,7 @@
 				}
 
 				start = end + 1;
-				end = directory.indexOf(File.separator,
+				end = directory.indexOf("/",
 						start);
 
 				// 妫�鏌ユ墍鏈夌洰褰曟槸鍚﹀垱寤哄畬姣�
@@ -541,7 +541,7 @@
 	public static void main(String[] args) throws Exception {
 		try {
 			FtpUtil ftpUtil = new FtpUtil("175.27.187.84", 21, "ftpuser","doumee168" );
-			ftpUtil.uploadOnlineFile("https://profile-avatar.csdnimg.cn/default.jpg!1", "test"+File.separator, UUID.randomUUID().toString()+"test.jpg");
+			ftpUtil.uploadOnlineFile("https://profile-avatar.csdnimg.cn/default.jpg!1", "test"+"/", UUID.randomUUID().toString()+"test.jpg");
 			/*FtpUtil myFtp = new FtpUtil("106.15.54.228", 21, "ftptlg",
 					"tlg168.com");
 			System.out.println(myFtp.upload("D:\\devices.sql", "/1111/devices.sql"));
@@ -631,7 +631,7 @@
 			String remoteDirectoryPath) throws Exception {
 		File src = new File(localDirectory);
 		try {
-			remoteDirectoryPath =  remoteDirectoryPath  + File.separator;
+			remoteDirectoryPath =  remoteDirectoryPath  + "/";
 			boolean makeDirFlag = this.ftpClient.makeDirectory(remoteDirectoryPath);
 		}catch (IOException e) {
 			e.printStackTrace();
@@ -645,7 +645,7 @@
 			String tPath = remoteDirectoryPath+f.getName();
 			if (!f.isDirectory()) {
 
-				int dNum = getNumFromStr(tPath,File.separator.toCharArray()[0]);
+				int dNum = getNumFromStr(tPath,"/".toCharArray()[0]);
 				uploadFile(f, tPath);
 				if(dNum -2>=0){
 					for (int i = 0; i < dNum-1; i++) {
@@ -654,7 +654,7 @@
 				}
 			}else{
 				uploadDirectory(srcName,
-						tPath+File.separator);
+						tPath+"/");
 			}
 		}
 		return true;
@@ -666,7 +666,7 @@
 	 * */
 	public boolean delDirectory(String pathName ) throws Exception {
 		try {
-			this.ftpClient.changeWorkingDirectory( pathName.substring(0, pathName.lastIndexOf(File.separator)) );
+			this.ftpClient.changeWorkingDirectory( pathName.substring(0, pathName.lastIndexOf("/")) );
 			ftpClient.removeDirectory(pathName);
 		}catch (IOException e) {
 			e.printStackTrace();

--
Gitblit v1.9.3