使用spring-integration-ftp,在指定目录下每天动态生成一个日期目录,将文件上传至该目录下
由于本人从事信贷系统开发工作,在工作中经常要和核心系统、支付系统、用户中心系统有文件交互(日终批量系统使用spring batch),所以需要使用ftp文件上传下载。以前文件的上传下载都是使用apache的ftp开发框架解决,代码量虽然不大,但是要写的代码还是不少。本次决定使用spring-integration解决方案。
- 导入ftp的依赖
<!-- 项目使用的spring boot 1.5.4、spring batch -->
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-ftp</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
- 配置ftp服务器信息
uc.ftp.host=localhost
uc.ftp.port=2121
uc.ftp.username=xulong
uc.ftp.password=123456
remote.directory=/share
- 配置ftp配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
xsi:schema