|
FTP has been edited by Claus Ibsen (Jul 26, 2008). Change summary: CAMEL-654 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]
As this component is an extension to the File component the options from this parent component is also available. 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. 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"); } }; } See Also |
Unsubscribe or edit your notifications preferences
