From a41d1410330eb9d543c9ab994b757ea1c54d1a92 Mon Sep 17 00:00:00 2001
From: tangzy <tangzy123456>
Date: Sat, 21 Aug 2021 16:22:52 +0800
Subject: [PATCH] 1.ftp
---
src/main/java/org/springblade/modules/FTP/monitor.java | 35 +++++++++++++++++++++++++++++++----
1 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/springblade/modules/FTP/monitor.java b/src/main/java/org/springblade/modules/FTP/monitor.java
index 324a9e7..9750b3f 100644
--- a/src/main/java/org/springblade/modules/FTP/monitor.java
+++ b/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();
}
--
Gitblit v1.9.3