|
FTP has been edited by Claus Ibsen (Aug 04, 2008). Change summary: CAMEL-764 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]
New default behavior for FTP/SFTP-Consumers in Camel 1.5By default the file is only consumer if the file is not in the progress of being written. 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. Message HeadersThe following message headers is provided in the message.
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. Known issuesWhen 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.exclusiveRead option. In Camel 1.5 the file consumer will avoid polling files that is currently in the progress of being written (see option consumer.exclusiveRead). However this requires Camel being able to rename the file for its testing. If the Camel user hasn't this rights on the file system, you can set this option to false to revert the change to the default behavior of Camel 1.4 or older. 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"); } }; } Debug loggingThis component has log level TRACE that can be helpful if you have problems. See Also |
Unsubscribe or edit your notifications preferences
