whycxzp
2023-03-01 93a16e3707b870856594e89b950174b64bb7d6cd
src/main/java/com/whyc/service/FtpService.java
@@ -12,12 +12,13 @@
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();
@@ -29,11 +30,21 @@
            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();
        }