智慧保安后台管理-外网项目备份
tangzy
2021-08-21 00b43011dc4aa059731f7f9c8553ec9b1b728dfe
src/main/java/org/springblade/modules/FTP/monitor.java
@@ -8,6 +8,7 @@
import java.io.IOException;
import java.io.InputStream;
@Component
public class monitor {
   //ftp服务器IP地址
@@ -19,9 +20,14 @@
   //ftp服务器密码
   private static String ftpPassword = "Yly@123";
   //ftp服务器路径
   private static String ftpPath = "anbao/sql.json";
   private static String ftpPath = "anbao/nsql.json";
   //本地路径
   private static String localPath = "D:\\anbao";
   //文件名
   private static String fileName = "nsql.json";
   @Scheduled(cron = "*/5 * * * * ?")
   @Scheduled(cron = "*/30 * * * * ?")
   public static boolean isFTPFileExist() {
      FTPClient ftp = new FTPClient();
@@ -73,15 +79,36 @@
         InputStream is = ftp.retrieveFileStream(new String(file.getBytes("GBK"), FTP.DEFAULT_CONTROL_ENCODING));
         if (is == null || ftp.getReplyCode() == FTPReply.FILE_UNAVAILABLE) {
            System.out.println(false);
            return false;
         }
         if (is != null) {
            System.out.println(true);
            is.close();
            //把文件下载到本地
            FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName);
            //
            String s = OutJson.TestJson();
            //sql语句
            String sql = OutJson.stringReplace(s);
            //判断是否是新增,删除,修改
            String substring = sql.substring(0, 2);
            //新增
            if (substring.equals("in")){
               //运行sql语句
               MysqlCenlint.inster(sql);
            }
            //修改
            else if (substring.equals("up")){
            }
            //删除
            else {
            }
            //删除本地文件
            MysqlCenlint.delete();
            FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "nsql.json");
            is.close();
            ftp.completePendingCommand();
         }