| | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | |
| | | import static org.springblade.common.config.FtpConfig.*; |
| | | |
| | | |
| | | @Component |
| | | public class monitor { |
| | | //ftp服务器IP地址 |
| | | private static String ftpHost = "192.168.0.105"; |
| | | //ftp服务器端口 |
| | | private static int ftpPort = 21; |
| | | //ftp服务器用户名 |
| | | private static String ftpUserName = "yly"; |
| | | //ftp服务器密码 |
| | | private static String ftpPassword = "Yly@123"; |
| | | //ftp服务器路径 |
| | | private static String ftpPath = "anbao/"; |
| | | //本地路径 |
| | | private static String localPath = "D:\\anbao"; |
| | | //文件名 |
| | | //private static String fileName = "nsql.json"; |
| | | |
| | | |
| | | @Scheduled(cron = "*/30 * * * * ?") |
| | | // @Scheduled(cron = "*/30 * * * * ?") |
| | | public static boolean isFTPFileExist() { |
| | | |
| | | FTPClient ftp = new FTPClient(); |
| | | |
| | | try { |
| | | |
| | | // 连接ftp服务器 |
| | | // System.out.println("ftpHost = " + ftpHost); |
| | | |
| | | ftp.connect(ftpHost, ftpPort); |
| | | |
| | | // 登陆 |
| | | |
| | | ftp.login(ftpUserName, ftpPassword); |
| | | |
| | | // 检验登陆操作的返回码是否正确 |
| | | |
| | | if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) { |
| | |
| | | //ftp.changeWorkingDirectory(new String(dir.getBytes("GBK"), FTP.DEFAULT_CONTROL_ENCODING)); |
| | | |
| | | // 检验文件是否存在 |
| | | ftp.changeWorkingDirectory(ftpPath); |
| | | FTPFile[] files = ftp.listFiles(); |
| | | if (files.length==0){ |
| | | return false; |
| | |
| | | } |
| | | } |
| | | //删除本地文件 |
| | | MysqlCenlint.deletes(fileName); |
| | | //MysqlCenlint.deletes(fileName); |
| | | MysqlCenlint.deletess(fileName); |
| | | FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName); |
| | | FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, fileName); |
| | | is.close(); |
| | | ftp.completePendingCommand(); |
| | | } |
| | |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | |
| | | System.out.println("ftp连接失败"); |
| | | e.printStackTrace(); |
| | | |
| | | } finally { |