Spring与ftp集成以使用文件执行操作

时间:2015-11-10 07:09:26

标签: spring-integration

我想从ftp读取文件并将其存储在本地,并在本地存储后我想用java代码处理该文件。成功处理文件后,我想将其移动到另一个目录。如何使用与ftp的弹簧集成有效地完成它

public class FtpFileHandler {

public File ftpFileUserHandler(@Header("timestamp")  String timestamp,  File file){
    try {
        String filename = file.getName();
        String extension = FilenameUtils.getExtension(filename);                            

        }
        return file;
    } catch ( IOException | org.json.simple.parser.ParseException e) {
        Utility.exceptionLogger(e);
        return file;
    }
}       

}

                                        

<bean id="ftpFileHandlerService" class="com.aaa.clear.integration.service.impl.FtpFileHandler" />

<!--  HR Integration Start -->
<int-ftp:inbound-channel-adapter id="ftpInbound"                                        
                                 session-factory="ftpSessionFactory"
                                 charset="UTF-8"                                     
                                 auto-create-local-directory="true"
                                 delete-remote-files="true"    
                                 filename-regex=".*\.(txt)$"                        
                                 remote-directory="/FTP Test"
                                 remote-file-separator="/"
                                 preserve-timestamp="true"              
                                 temporary-file-suffix=".writing"
                                 local-directory="#{systemProperties['aaa']}/clear/integration/download/user">
                                <int:poller fixed-rate="180000" />
</int-ftp:inbound-channel-adapter>

<int:service-activator id="" input-channel="ftpInbound" output-channel="ftpOutbound" ref="ftpFileHandlerService" method="ftpFileUserHandler" >      
</int:service-activator>    

<int-ftp:outbound-channel-adapter id="ftpOutbound" session-factory="ftpSessionFactory" auto-create-directory="true"
        remote-directory="/FTP Test/processed/user"/>

1 个答案:

答案 0 :(得分:0)