| | |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | import static org.springblade.common.config.FtpConfig.*; |
| | | |
| | |
| | | @Component |
| | | public class Monitor { |
| | | |
| | | @Scheduled(cron = "*/1 * * * * ?") |
| | | @Scheduled(cron = "*/10 * * * * ?") |
| | | public static boolean isFTPFileExist() { |
| | | |
| | | FTPClient ftp = new FTPClient(); |
| | |
| | | return false; |
| | | } |
| | | |
| | | System.out.println("ftp 连接成功!"); |
| | | System.out.println("ftp 连接成功!时间: "+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
| | | |
| | | //被动模式,文件上传不成功会有提示 |
| | | ftp.enterLocalActiveMode(); |
| | |
| | | ftp.changeWorkingDirectory(ftpPath); |
| | | FTPFile[] files = ftp.listFiles(); |
| | | if (files.length == 0) { |
| | | ftp.disconnect(); |
| | | return false; |
| | | } else { |
| | | for (FTPFile file : files) { |
| | | fileName = file.getName(); |
| | | fileName = file.getName(); |
| | | InputStream is = ftp.retrieveFileStream(new String(fileName.getBytes("GBK"), FTP.DEFAULT_CONTROL_ENCODING)); |
| | | if (null == is) { |
| | | ftp.disconnect(); |
| | | return false; |
| | | } else { |
| | | String substring1 = fileName.substring(0, 1); |
| | |
| | | ftp.completePendingCommand(); |
| | | } |
| | | } |
| | | ftp.disconnect(); |
| | | return true; |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | MysqlCenlint.deletess(fileName); |
| | | FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", fileName); |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if (ftp.isConnected()) { |
| | | try { |
| | | ftp.disconnect(); |
| | | } catch (IOException io) { |
| | | io.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | } |