| | |
| | | import com.whyc.dto.FileDirPath; |
| | | import com.whyc.dto.FtpHelper; |
| | | import com.whyc.dto.ZipUtils; |
| | | import com.whyc.util.ActionUtil; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.util.Date; |
| | | |
| | | @Service |
| | | @EnableScheduling // 2.开启定时任务 |
| | | public class FtpService { |
| | | //定时上传指定目录下文件 |
| | | @Scheduled(cron = "0/20 30 17 * * ?") |
| | | @Scheduled(cron = "59 59 23 * * ?") |
| | | private void sendFtpFile(){ |
| | | FtpHelper ftp = new FtpHelper(YamlProperties.ftpIp, YamlProperties.ftpPort, YamlProperties.ftpUserName, YamlProperties.ftpPassword); |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | String root=fileDirName+File.separator+"face"; |
| | | String rootFace=fileDirName+File.separator+"face"; |
| | | String rootDoc=fileDirName+File.separator+"doc_file"; |
| | | String timeStr= ActionUtil.sdfwithFTP.format(new Date()); |
| | | try { |
| | | FileOutputStream fos = new FileOutputStream(new File(root+".zip")); |
| | | ZipUtils.toZip(root, fos,true); |
| | | File file = new File(root+".zip"); |
| | | ftp.uploadFile(file, "face.zip"); |
| | | FileOutputStream forootFace = new FileOutputStream(new File(rootFace+".zip")); |
| | | 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")); |
| | | ZipUtils.toZip(rootDoc, forootDoc,true); |
| | | File filerootDoc = new File(rootDoc+".zip"); |
| | | ftp.uploadFile(filerootDoc, timeStr+"/doc_file.zip"); |
| | | filerootDoc.delete(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |