| | |
| | | package org.springblade.modules.FTP; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import org.apache.commons.net.ftp.FTP; |
| | | import org.apache.commons.net.ftp.FTPClient; |
| | | import org.apache.commons.net.ftp.FTPFile; |
| | |
| | | import java.io.InputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.SocketException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static org.springblade.common.config.FtpConfig.*; |
| | | |
| | |
| | | * @return |
| | | */ |
| | | public static Result isFTPFileExist(String uuid) { |
| | | String name = "ni"+uuid; |
| | | // System.out.println("uuid = " + uuid); |
| | | //创建 ftp 对象 |
| | | FTPClient ftp = new FTPClient(); |
| | |
| | | if (files.length==0){ |
| | | return new Result(400,null,"未读取到文件",null); |
| | | } else { |
| | | boolean flag = false; |
| | | for (FTPFile file : files){ |
| | | String fileName = file.getName(); |
| | | if (fileName.contains("ni")){ |
| | | if (fileName.equals(name)){ |
| | | System.out.println("-------接收到内网回传的文件: " + fileName); |
| | | //把文件下载到本地 |
| | | FtpUtil.downloadFtpFile(ftpHost, ftpUserNameIn, ftpPasswordIn, ftpPort, ftpPath, localPath, fileName); |
| | | // 解析数据 |
| | | String s = OutJson.TestJson(fileName); |
| | | String json = OutJson.TestJson(fileName); |
| | | //数据处理 |
| | | Result result = DataHandler.handler(s,uuid); |
| | | //匹配上了删除文件 |
| | | if (result.getCode()==200) { |
| | | flag = true; |
| | | Map map = JSON.parseObject(json, Map.class); |
| | | //获取结果 |
| | | Object o = map.get(uuid); |
| | | if (null!= o || !o.equals("")){ |
| | | Result result = JSON.parseObject(o.toString(), Result.class); |
| | | System.out.println("读取返回结果 result = " + result); |
| | | //删除本地文件 |
| | | MysqlCenlint.deletess(fileName); |
| | | //删除 ftp 文件 |
| | | FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserNameIn, ftpPasswordIn, ftpPath, fileName); |
| | | // ftp.dele(fileName); |
| | | List<Result> list = new ArrayList<>(); |
| | | list.add(result); |
| | | //返回 |
| | | return result; |
| | | return new Result(200,null,list); |
| | | } |
| | | ftp.completePendingCommand(); |
| | | ftp.logout(); |
| | | } |
| | | } |
| | | // if (!flag){ |
| | | // ftp.logout(); |
| | | // } |
| | | ftp.completePendingCommand(); |
| | | ftp.logout(); |
| | | return new Result(400,null,"未读取到对应的文件",null); |
| | | } |
| | | } catch (Exception e) { |