ftp
zengh
2022-05-18 1c93194c661ff0806cb8cbfdbcaba81693ee9797
src/main/java/org/springblade/modules/FTP/Monitor.java
@@ -4,11 +4,15 @@
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.springblade.modules.system.entity.User;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import static org.springblade.common.config.FtpConfig.*;
@@ -16,7 +20,7 @@
@Component
public class Monitor {
   @Scheduled(cron = "*/1 * * * * ?")
   @Scheduled(cron = "*/30 * * * * ?")
   public static boolean isFTPFileExist() {
      FTPClient ftp = new FTPClient();
@@ -33,6 +37,8 @@
            ftp.disconnect();
            return false;
         }
         System.out.println("ftp 连接成功!时间: "+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
         //被动模式,文件上传不成功会有提示
         ftp.enterLocalActiveMode();
@@ -93,7 +99,7 @@
                     MysqlCenlint.deletess(fileName);
                     //删除 ftp 文件
                     FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName);
                  }else if(substring1.equals("ol")){
                  }else if(substring1.equals("l")){
                     //用户集合数据
                     //获取对象字符串
                     String json = OutJson.TestJson(fileName);
@@ -103,6 +109,36 @@
                     MysqlCenlint.deletess(fileName);
                     //删除 ftp 文件
                     FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName);
                  }else if(substring1.equals("t")){
                     //培训报名数据
                     //获取对象字符串
                     String json = OutJson.TestJson(fileName);
                     //数据处理
                     DataHanlder.handlerListTrain(json);
                     //删除本地文件
                     MysqlCenlint.deletess(fileName);
                     //删除 ftp 文件
                     FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName);
                  }else if(substring1.equals("s")){
                     //获取保安员证编号数据
                     //获取对象字符串
                     String json = OutJson.TestJson(fileName);
                     //数据处理
                     DataHanlder.handlerSecurityNumerBit(json);
                     //删除本地文件
                     MysqlCenlint.deletess(fileName);
                     //删除 ftp 文件
                     FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName);
                  }
//                  else if(substring1.equals("f")){
//                     //把文件下载到本地(图片文件类),测试内外网使用同一台服务器
//                     FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, minioPath, fileName);
//                     FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName);
//                  }
                  else {
                     //把文件下载到本地(图片文件类),ftp 内外网服务器分开时使用
                     FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, minioPath, fileName);
                     FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName);
                  }
                  //删除本地文件,ftp 文件没有对应读取的不删除
                  MysqlCenlint.deletess(fileName);