| | |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @EnableScheduling // 2.开启定时任务 |
| | | public class FtpService { |
| | | //定时上传指定目录下文件 |
| | | @Scheduled(cron = "59 59 23 * * ?") |
| | | @Scheduled(cron = "59 59 23 ? * FRI") |
| | | private void sendFtpFile(){ |
| | | FtpHelper ftp = new FtpHelper(YamlProperties.ftpIp, YamlProperties.ftpPort, YamlProperties.ftpUserName, YamlProperties.ftpPassword); |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | |
| | | ZipUtils.toZip(rootFace, forootFace,true); |
| | | File filerootFace = new File(rootFace+".zip"); |
| | | ftp.uploadFile(filerootFace, timeStr+"/face.zip"); |
| | | filerootFace.delete(); |
| | | |
| | | FileOutputStream forootDoc = new FileOutputStream(new File(rootDoc+".zip")); |
| | | /*FileOutputStream forootDoc = new FileOutputStream(new File(rootDoc+".zip")); |
| | | ZipUtils.toZip(rootDoc, forootDoc,true); |
| | | File filerootDoc = new File(rootDoc+".zip"); |
| | | ftp.uploadFile(filerootDoc, timeStr+"/doc_file.zip"); |
| | | filerootDoc.delete();*/ |
| | | List<File> list=ftp.getFileList(rootDoc); |
| | | if(list!=null&&list.size()>0){ |
| | | for (File file:list) { |
| | | String name=file.getPath().substring(file.getPath().lastIndexOf("doc_file")); |
| | | String pathName=timeStr+"/"+name.replace("\\","/"); |
| | | ftp.uploadFile(file, pathName); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |