From dd899673f3ff75ad59ae43afd124ef8ef0fc0180 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Wed, 27 Apr 2022 17:24:12 +0800
Subject: [PATCH] ftp 同步修改调整
---
src/main/java/org/springblade/modules/FTP/Monitor.java | 128 +++++++++++++-----------------------------
1 files changed, 41 insertions(+), 87 deletions(-)
diff --git a/src/main/java/org/springblade/modules/FTP/Monitor.java b/src/main/java/org/springblade/modules/FTP/Monitor.java
index 63561dc..52c6e41 100644
--- a/src/main/java/org/springblade/modules/FTP/Monitor.java
+++ b/src/main/java/org/springblade/modules/FTP/Monitor.java
@@ -21,8 +21,6 @@
@Component
public class Monitor {
-
-
/**
* 读取文件(对象)
* @param uuid 随机数
@@ -85,6 +83,10 @@
//返回
return new Result(202,null,result.getMsg(),null);
}
+ if (result.getCode()==203) {
+ //返回
+ return new Result(203,null,result.getMsg(),null);
+ }
}
}
return new Result(400,null,"未读取到对应的文件",null);
@@ -105,10 +107,10 @@
}
/**
- * 读取文件
+ * 读取内外推送的文件,每30秒读取一次
* @return
*/
- // @Scheduled(cron = "*/30 * * * * ?")
+ @Scheduled(cron = "*/30 * * * * ?")
public static boolean isFTPFileExist() {
FTPClient ftp = new FTPClient();
try {
@@ -137,110 +139,62 @@
return false;
}
else {
- for (FTPFile file : files){
+ for (FTPFile file : files) {
String fileName = file.getName();
InputStream is = ftp.retrieveFileStream(new String(fileName.getBytes("GBK"), FTP.DEFAULT_CONTROL_ENCODING));
- String substring1 = fileName.substring(0, 1);
- if (substring1.equals("n")){
- //把文件下载到本地
- FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName);
- //
- String s = OutJson.TestJson(fileName);
- //sql语句
- String sql = OutJson.stringReplace(s);
- String[] split = sql.split(";");//以逗号分割
- for (String sqls : split) {
- //判断是否是新增,删除,修改
- String substring = sqls.substring(0, 2);
- //新增
- if (substring.equals("in")) {
- //运行sql语句
- MysqlCenlint.inster(sqls);
+ if (null == is) {
+ return false;
+ } else {
+ String substring1 = fileName.substring(0, 4);
+ if (substring1.equals("nsql")) {
+ //把文件下载到本地
+ FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName);
+ //
+ String s = OutJson.TestJson(fileName);
+ //sql语句
+ String sql = OutJson.stringReplace(s);
+ String[] split = sql.split(";");//以逗号分割
+ for (String sqls : split) {
+ //判断是否是新增,删除,修改
+ String substring = sqls.substring(0, 2);
+ //新增
+ if (substring.equals("in")) {
+ //运行sql语句
+ MysqlCenlint.inster(sqls);
+ }
+ //修改
+ else if (substring.equals("up")) {
+ MysqlCenlint.update(sqls);
+ }
+ //删除
+ else {
+ MysqlCenlint.delete(sqls);
+ }
}
- //修改
- else if (substring.equals("up")) {
- MysqlCenlint.update(sqls);
- }
- //删除
- else {
- MysqlCenlint.delete(sqls);
- }
+ //删除本地服务器文件
+ MysqlCenlint.deletess(fileName);
+ //删除 ftp 服务器文件
+ FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, fileName);
}
- //删除本地文件
- //MysqlCenlint.deletes(fileName);
- MysqlCenlint.deletess(fileName);
- FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, fileName);
+ //关闭流
is.close();
ftp.completePendingCommand();
}
+ return true;
}
- return true;
}
-
- //InputStream is = ftp.retrieveFileStream(new String(file.getBytes("GBK"), FTP.DEFAULT_CONTROL_ENCODING));
-
-// if (is == null || ftp.getReplyCode() == FTPReply.FILE_UNAVAILABLE) {
-// return false;
-//
-// }
-//
-// if (is != null) {
-// //把文件下载到本地
-// FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName);
-// //
-// String s = OutJson.TestJson();
-// //sql语句
-// String sql = OutJson.stringReplace(s);
-// String[] split = sql.split(";");//以逗号分割
-// for (String sqls : split) {
-// //判断是否是新增,删除,修改
-// String substring = sqls.substring(0, 2);
-// //新增
-// if (substring.equals("in")) {
-// //运行sql语句
-// MysqlCenlint.inster(sqls);
-// }
-// //修改
-// else if (substring.equals("up")) {
-// MysqlCenlint.update(sqls);
-// }
-// //删除
-// else {
-// MysqlCenlint.delete(sqls);
-// }
-// }
-// //删除本地文件
-// MysqlCenlint.delete();
-// FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "nsql.json");
-// is.close();
-// ftp.completePendingCommand();
-//
-// }
-
-
} catch (Exception e) {
System.out.println("ftp连接失败");
e.printStackTrace();
-
} finally {
-
if (ftp != null) {
-
try {
-
ftp.disconnect();
-
} catch (IOException e) {
-
e.printStackTrace();
-
}
-
}
-
}
-
return false;
-
}
}
--
Gitblit v1.9.3