Move files on ftp

笑着哭i 提交于 2019-12-13 00:22:47

问题


I am working with Apache Camel Spring Framework. I have a component FTP (to get files from ftp) and Bean (process files and store it in database). All I have missing is when I process those files and store it in database I have to check if insert or update was successful (this is working too). If the action is successful I have to move the file to another folder on ftp, if it is unsuccessful I have to move it to a different folder on ftp.

So I am asking if there is a simple way to copy the file from location dirA to dirB


回答1:


Everything you need to know is here Apache Camel: File2 Search for move and moveFailed.

If insert was not successful you may throw a CamelException. Camel will then move the file to the folder you specified.

ftp://10.10.10.10/toRead?move=inDB&moveFailed=notInDB



回答2:


As I do not have your code, I will just answer by showing how I would manage such case:

Make two separate routes according to the result of the bean processing.

from("{{your.ftp.source}}")
    .bean( new ProcessAndStoreFileBean())
    .choice()
        .when(property("fileProcessingResult").equalsTo(true))
            .to("ftp://yourserver/Destination/Folder/Success")
        .otherwise()
            .to("ftp://yourserver/Destination/Folder/Failure")
    .end();

and in the Bean method I would just make:

class ProcessAndStoreFileBean {

    @Handler
    public void processAndSaveInDb(Exchange exchange){

        // many line to do the job...

        if( success ) 
            exchange.setProperty("fileProcessingResult", true);
        else{
            exchange.setProperty("fileProcessingResult", false);
    }
}


来源:https://stackoverflow.com/questions/31556558/move-files-on-ftp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!