tangzy
2021-08-21 a41d1410330eb9d543c9ab994b757ea1c54d1a92
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,7 +20,12 @@
   //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 * * * * ?")
   public static boolean isFTPFileExist() {
@@ -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();
         }