package com.whyc.service;
|
|
import com.whyc.constant.YamlProperties;
|
import com.whyc.dto.FileDirPath;
|
import com.whyc.dto.FtpHelper;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Service;
|
|
import java.io.File;
|
|
@Service
|
@EnableScheduling // 2.开启定时任务
|
public class FtpService {
|
@Autowired(required = false)
|
private FtpHelper ftpHelper;
|
|
//定时上传指定目录下文件
|
@Scheduled(cron = "0/20 41 16 * * ?")
|
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";
|
File file = new File(root+File.separator+"2.doc");
|
try {
|
ftp.uploadFile(file, "test/2.doc");
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
ftp.disconnect();
|
}
|
}
|