You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by erik_romson <er...@zenior.no> on 2014/11/07 15:57:13 UTC

how to check that a file exists in ftpserver

Hi all,
I'm trying to understand how to fix the following.

setup:
1: send in a file to ftpserver
2: the file is later moved to another folder by another process

in a route, I want to
1: read file name(s) from database (select filename from atable where
state='file_not_moved')
2: check that file exists in ftpserver/folder
3: [true] update  atable set status='file_moved' where
state='file_not_moved' and filename=:filname

I haven't understood the *best* way of doing this

Scenario1 (using IdempotentRepository )
I have however solved this to poll the complete folder and a custom
IdempotentRepository (that updates the state in the table). This however
scans the complete folder (I use a FileFilter to limit it somewhat) and the
folder can be quite big (grows with 6000 files a day)

from("file://urltoprocessedfolder&noop=true&idempotent=true&idempotentRepository=#idempotentXmlProcessed&sortBy=file:modified?filter=#xmlFilter"
)
                        .log(LoggingLevel.ERROR, logger, "writing idempotent
to ${id}")
                        .to("mock:end");


Scenario2 (using enrich)

from("sql:select filename from atable where state='file_not_moved'")
   
.enrich("file://urltoprocessedfolder?noop=true&readLock=none&fileName=${header.filename}");

this works but it seems shady somehow


Is the *best* way to create a predicate that actually check if the file
exists? like (not correct code)

 from("sql:select filename from atable where state='file_not_moved'")
            .choice()
                .when(predicateThatChecksIfFileExists(${filename}))
                    .to(""sql:update atable set state='file_moved' where
filename=:#filename")
                .otherwise()
                    .to("dummy:a");

as soon I use the ftpcomponent as a producer, it creates the file...



--
View this message in context: http://camel.465427.n5.nabble.com/how-to-check-that-a-file-exists-in-ftpserver-tp5758705.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how to check that a file exists in ftpserver

Posted by "rahul.lambat@gmail.com" <ra...@gmail.com>.
I Also have similar question just i want to check if file not present at Sftp
location then thow exception..



--
View this message in context: http://camel.465427.n5.nabble.com/how-to-check-that-a-file-exists-in-ftpserver-tp5758705p5790206.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how to check that a file exists in ftpserver

Posted by Claus Ibsen <cl...@gmail.com>.
Using noop=true and download=false can be used to check if if a file exists.

And you can set fastExistsCheck=true, and stepwise=false to scan much less.



On Sat, Nov 8, 2014 at 8:51 AM, erik_romson <er...@zenior.no> wrote:
> Thanks for a quick reply.
>
> I'm sorry but you have to spell it out to me, do you refer to the
> IdempotentRepository way of doing it? I was aware of that but option (I have
> been testing it with the filecomponent) but still, having to scan the entire
> ftprepo seems a bit excessive.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/how-to-check-that-a-file-exists-in-ftpserver-tp5758705p5758747.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: how to check that a file exists in ftpserver

Posted by erik_romson <er...@zenior.no>.
Thanks for a quick reply.

I'm sorry but you have to spell it out to me, do you refer to the
IdempotentRepository way of doing it? I was aware of that but option (I have
been testing it with the filecomponent) but still, having to scan the entire
ftprepo seems a bit excessive.



--
View this message in context: http://camel.465427.n5.nabble.com/how-to-check-that-a-file-exists-in-ftpserver-tp5758705p5758747.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how to check that a file exists in ftpserver

Posted by Claus Ibsen <cl...@gmail.com>.
There is a download=false option you can set. See details at the camel ftp doc

On Fri, Nov 7, 2014 at 3:57 PM, erik_romson <er...@zenior.no> wrote:
> Hi all,
> I'm trying to understand how to fix the following.
>
> setup:
> 1: send in a file to ftpserver
> 2: the file is later moved to another folder by another process
>
> in a route, I want to
> 1: read file name(s) from database (select filename from atable where
> state='file_not_moved')
> 2: check that file exists in ftpserver/folder
> 3: [true] update  atable set status='file_moved' where
> state='file_not_moved' and filename=:filname
>
> I haven't understood the *best* way of doing this
>
> Scenario1 (using IdempotentRepository )
> I have however solved this to poll the complete folder and a custom
> IdempotentRepository (that updates the state in the table). This however
> scans the complete folder (I use a FileFilter to limit it somewhat) and the
> folder can be quite big (grows with 6000 files a day)
>
> from("file://urltoprocessedfolder&noop=true&idempotent=true&idempotentRepository=#idempotentXmlProcessed&sortBy=file:modified?filter=#xmlFilter"
> )
>                         .log(LoggingLevel.ERROR, logger, "writing idempotent
> to ${id}")
>                         .to("mock:end");
>
>
> Scenario2 (using enrich)
>
> from("sql:select filename from atable where state='file_not_moved'")
>
> .enrich("file://urltoprocessedfolder?noop=true&readLock=none&fileName=${header.filename}");
>
> this works but it seems shady somehow
>
>
> Is the *best* way to create a predicate that actually check if the file
> exists? like (not correct code)
>
>  from("sql:select filename from atable where state='file_not_moved'")
>             .choice()
>                 .when(predicateThatChecksIfFileExists(${filename}))
>                     .to(""sql:update atable set state='file_moved' where
> filename=:#filename")
>                 .otherwise()
>                     .to("dummy:a");
>
> as soon I use the ftpcomponent as a producer, it creates the file...
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/how-to-check-that-a-file-exists-in-ftpserver-tp5758705.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/