package com.yang.task.utils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.yang.common.hq.constant.RedisKey;
import com.yang.common.ushq.constant.UsRedisKey;
import com.yang.task.utils.IISFtpClient.DownloadStatus;
import redis.clients.jedis.JedisCluster;
@Component
public class UsIISFtpClient {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private FTPClient ftpClient = new FTPClient();
@Value("${us.iis.ftp.url}")
private String url;
@Value("${us.iis.ftp.username}")
private String username;
@Value("${us.iis.ftp.password}")
private String password;
// 枚举类DownloadStatus代码
public enum DownloadStatus {
Remote_File_Noexist, // 远程文件不存在
Download_Success, // 下载文件成功
Download_Failed // 下载文件失败
}
java ftp 断点下载,异常重连
最新推荐文章于 2024-06-30 03:13:33 发布
本文介绍了如何使用Java进行FTP断点下载,通过缓存文件路径并利用递归方式确保未完成的下载能继续进行。为了避免FTPClient的listFile操作导致的卡死问题,采用了Future配合自定义超时策略。如有疑问,可在评论区留言讨论。
摘要由CSDN通过智能技术生成