From 318105e308c277420dd8f080afa35102ddddc7db Mon Sep 17 00:00:00 2001
From: whycxzp <perryhsu@163.com>
Date: 星期一, 25 九月 2023 15:39:26 +0800
Subject: [PATCH] 更新

---
 src/main/java/com/whyc/service/FtpService.java |   69 +++++++++++++++++++++-------------
 1 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/src/main/java/com/whyc/service/FtpService.java b/src/main/java/com/whyc/service/FtpService.java
index 9905c70..3fa2a1f 100644
--- a/src/main/java/com/whyc/service/FtpService.java
+++ b/src/main/java/com/whyc/service/FtpService.java
@@ -25,7 +25,7 @@
 @Service
 @EnableScheduling   // 2.寮�鍚畾鏃朵换鍔�
 public class FtpService {
-    //瀹氭椂涓婁紶鎸囧畾鐩綍涓嬫枃浠�
+    //瀹氭椂涓婁紶鎸囧畾鐩綍涓嬫枃浠�,姣忓懆浜斿噷鏅ㄥ紑鍚浠�
     @Scheduled(cron = "59 59 23 ? * FRI")
     //@Scheduled(cron = "0/10 * * * * ?")
     private void sendFtpFile() throws IOException, FTPException, InterruptedException, ParseException {
@@ -37,44 +37,61 @@
         for (int i = 0; i < dirList2.size()-3; i++) {
             ftpRemote.deleteDir(dirList2.get(i));
         }
-        ftpRemote.disconnect();
+
 
 
         String fileDirName = FileDirPath.getFileDirName();
         
         String rootDoc=fileDirName+File.separator+"doc_file";
         String timeStr= ActionUtil.sdfwithFTP.format(new Date());
+        ftpRemote.mkdir(timeStr);
+        ftpRemote.disconnect();
         try {
 
             File docFile = new File(rootDoc);
-            File[] list = docFile.listFiles();
-            CountDownLatch latch = new CountDownLatch(list.length+1);
-            if(list!=null&&list.length>0){
-                for (File file:list) {
-                    new Thread(){
-                        @Override
-                        public void run() {
-                            //鍘嬬缉浼犺緭
-                            File fileZip = new File(file.getAbsolutePath() + ".zip");
-                            try {
-                                ZipUtils.toZip(file.getAbsolutePath(),new FileOutputStream(fileZip),true);
-                                String pathName=timeStr+"/doc_file/"+file.getName()+".zip";
-                                FtpHelper ftp = new FtpHelper(YamlProperties.ftpIp, YamlProperties.ftpPort, YamlProperties.ftpUserName, YamlProperties.ftpPassword);
-                                ftp.uploadFile(fileZip, pathName);
-                                fileZip.delete();
-                                ftp.disconnect();
-                                latch.countDown();
-                            } catch (Exception e) {
-                                e.printStackTrace();
-                                latch.countDown();
-                            }
-                        }
-                    }.start();
+            File[] fileList = docFile.listFiles();
+            List<File> list = Arrays.asList(fileList);
+            for (File file:list) {
+                //鍘嬬缉浼犺緭
+                File fileZip = new File(file.getAbsolutePath() + ".zip");
+                ZipUtils.toZip(file.getAbsolutePath(),new FileOutputStream(fileZip),true);
+                //System.out.println(fileZip.toString()+"鍘嬬缉瀹屾瘯");
+            }
+            //System.out.println("杩涜FTP浼犺緭涓�...");
+            CountDownLatch latch = new CountDownLatch(list.size()+1);
 
-                }
+            for (File file:list) {
+                new Thread(){
+                    @Override
+                    public void run() {
+                        //鍘嬬缉浼犺緭
+                        File fileZip = new File(file.getAbsolutePath() + ".zip");
+                        //System.out.println("绾跨▼鍐� 鍘嬬缉鍚庣殑鐩爣璺緞涓�:"+fileZip.toString());
+                        FtpHelper ftp = new FtpHelper(YamlProperties.ftpIp, YamlProperties.ftpPort, YamlProperties.ftpUserName, YamlProperties.ftpPassword);
+                        try {
+                            //ZipUtils.toZip(file.getAbsolutePath(),new FileOutputStream(fileZip),true);
+                            String pathName=timeStr+"/"+file.getName()+".zip";
+                            //System.out.println("浼犺緭鐩爣璺緞纭涓�:"+pathName);
+                            ftp.uploadFile2(fileZip, pathName);
+                            //System.out.println(fileZip+"浼犺緭瀹屾瘯");
+                            fileZip.delete();
+                            //System.out.println(fileZip+"浼犺緭涓浆鍘嬬缉鍖呭垹闄ゅ畬姣�");
+
+                            ftp.disconnect();
+                            latch.countDown();
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                            fileZip.deleteOnExit();
+                            ftp.disconnect();
+                            latch.countDown();
+                        }
+                    }
+                }.start();
+
             }
             latch.countDown();
             latch.await();
+            //System.out.println("浼犺緭瀹屾瘯");
         } catch (Exception e) {
             e.printStackTrace();
         }

--
Gitblit v1.9.1