|
FTP has been edited by Claus Ibsen (Nov 02, 2008). Change summary: CAMEL-1044 FTP/SFTP ComponentThis component provides access to remote file systems over the FTP and SFTP protocols. URI formatftp://[EMAIL PROTECTED]:port]/filename[?options] sftp://[EMAIL PROTECTED]:port]/filename[?options]
Options
New default behavior for FTP/SFTP-Consumers in Camel 1.5The consumer will always skip any file which name starts with a dot, such as ".", ".camel", ".m2" or ".groovy". Only files (not directories) is matched for valid filename if options such as: consumer.regexPattern, consumer.excludeNamePrefix, consumer.excludeNamePostfix is used. The consumer recursive option will be changed from true to false as the default value. We don't feel that Camel out-of-the-box should recursive poll. The consumer will not use timestamp algorithm for determine if a remote file is a new file - see warning section above. To use the old behavior of Camel 1.4 or older you can use the option consumer.timestamp=true. Exclusive Read LockThe new option consumer.exclusiveReadLock can be used to force Camel not to consume files that is currently in the progress of being written. However this option is default turned off, as it requires that the user has write access. There are other solutions to avoid consuming files that are currently being written over FTP, for instance you can write the a temporary destination and move the file after it has been written. Message HeadersThe following message headers can be used to affect the behavior of the component
Consumer propertiesWhen using FTPConsumer (downloading files from a FTP Server) the consumer specific properties from the File component should be prefixed with "consumer.". For example the delay option from File Component should be specified as "consumer.delay=30000" in the URI. See the samples or some of the unit tests of this component. Filename _expression_In Camel 1.5 we have support for setting the filename using an _expression_. This can be set either using the _expression_ option or as a string based File Language _expression_ in the org.apache.camel.file.name header. See the File Language for some samples. Known issuesSee the timestamp warning. When consuming files (downloading) you must use type conversation to either String or to InputStream for ASCII and BINARY file types. In Camel 1.4 or below Camel FTPConsumer will poll files regardless if the file is currently being written. See the consumer.exclusiveReadLock option. Also in Camel 1.3 since setNames is default false then you must explicitly set the filename using the setHeader _expression_ when consuming from FTP directly to File. private String ftpUrl = "ftp://[EMAIL PROTECTED]:21/public/downloads?password=admin&binary=false"; private String fileUrl = "file:myfolder/?append=false&noop=true"; return new RouteBuilder() { public void configure() throws Exception { from(ftpUrl).setHeader(FileComponent.HEADER_FILE_NAME, constant("downloaded.txt")).convertBodyTo(String.class).to(fileUrl); } }; Or you can set the option to true as illustrated below: private String ftpUrl = "ftp://[EMAIL PROTECTED]:21/public/downloads?password=admin&binary=false&consumer.setNames=true"; private String fileUrl = "file:myfolder/?append=false&noop=true"; return new RouteBuilder() { public void configure() throws Exception { from(ftpUrl).convertBodyTo(String.class).to(fileUrl); } }; SampleIn the sample below we setup Camel to download all the reports from the FTP server once every hour (60 min) as BINARY content and store it as files on the local file system. protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { // we use a delay of 60 minutes (eg. once pr. hour we poll the FTP server long delay = 60 * 60 * 1000L; // from the given FTP server we poll (= download) all the files // from the public/reports folder as BINARY types and store this as files // in a local directory. Camel will use the filenames from the FTPServer // notice that the FTPConsumer properties must be prefixed with "consumer." in the URL // the delay parameter is from the FileConsumer component so we should use consumer.delay as // the URI parameter name. The FTP Component is an extension of the File Component. from("ftp://[EMAIL PROTECTED]/public/reports?password=tiger&binary=true&consumer.delay=" + delay). to("file://target/test-reports"); } }; } Using _expression_ for filenamesIn this sample we want to move consumed files to a backup folder using today's date as a sub foldername: from(ftpUrl + "&_expression_=backup/${date:now:yyyyMMdd}/${file:name}").to("..."); See File Language for more samples. Debug loggingThis component has log level TRACE that can be helpful if you have problems. See Also |
Unsubscribe or edit your notifications preferences
