CAMEL-10401: Support chmod for ftp/ftps Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/27ed9cb4 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/27ed9cb4 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/27ed9cb4
Branch: refs/heads/master Commit: 27ed9cb4b9f99e70aa7bc86c673dd5f786aa607b Parents: 72f75a3 Author: eidottermihi <eidotterm...@gmail.com> Authored: Wed Oct 19 14:23:21 2016 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Oct 21 16:21:30 2016 +0200 ---------------------------------------------------------------------- .../camel-ftp/src/main/docs/ftp-component.adoc | 3 +- .../camel-ftp/src/main/docs/ftps-component.adoc | 3 +- .../component/file/remote/FtpConfiguration.java | 13 +++++++ .../component/file/remote/FtpOperations.java | 12 ++++++- .../file/remote/FromFileToFtpWithChmodTest.java | 36 ++++++++++++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/27ed9cb4/components/camel-ftp/src/main/docs/ftp-component.adoc ---------------------------------------------------------------------- diff --git a/components/camel-ftp/src/main/docs/ftp-component.adoc b/components/camel-ftp/src/main/docs/ftp-component.adoc index a2b1548..ee9104c 100644 --- a/components/camel-ftp/src/main/docs/ftp-component.adoc +++ b/components/camel-ftp/src/main/docs/ftp-component.adoc @@ -119,7 +119,7 @@ The FTP component has no options. // endpoint options: START -The FTP component supports 104 endpoint options which are listed below: +The FTP component supports 105 endpoint options which are listed below: {% raw %} [width="100%",cols="2,1,1m,1m,5",options="header"] @@ -163,6 +163,7 @@ The FTP component supports 104 endpoint options which are listed below: | tempFileName | producer | | String | The same as tempPrefix option but offering a more fine grained control on the naming of the temporary filename as it uses the File Language. | tempPrefix | producer | | String | This option is used to write the file using a temporary name and then after the write is complete rename it to the real name. Can be used to identify files being written and also avoid consumers (not using exclusive read locks) reading in progress files. Is often used by FTP when uploading big files. | allowNullBody | producer (advanced) | false | boolean | Used to specify if a null body is allowed during file writing. If set to true then an empty file will be created when set to false and attempting to send a null body to the file component a GenericFileWriteException of 'Cannot write null body to file.' will be thrown. If the fileExist option is set to 'Override' then the file will be truncated and if set to append the file will remain unchanged. +| chmod | producer (advanced) | | String | Allows you to set chmod on the stored file. For example chmod=640. | disconnectOnBatchComplete | producer (advanced) | false | boolean | Whether or not to disconnect from remote FTP server right after a Batch upload is complete. disconnectOnBatchComplete will only disconnect the current connection to the FTP server. | eagerDeleteTargetFile | producer (advanced) | true | boolean | Whether or not to eagerly delete any existing target file. This option only applies when you use fileExists=Override and the tempFileName option as well. You can use this to disable (set it to false) deleting the target file before the temp file is written. For example you may write big files and want the target file to exists during the temp file is being written. This ensure the target file is only deleted until the very last moment just before the temp file is being renamed to the target filename. This option is also used to control whether to delete any existing files when fileExist=Move is enabled and an existing file exists. If this option copyAndDeleteOnRenameFails false then an exception will be thrown if an existing file existed if its true then the existing file is deleted before the move operation. | keepLastModified | producer (advanced) | false | boolean | Will keep the last modified timestamp from the source file (if any). Will use the Exchange.FILE_LAST_MODIFIED header to located the timestamp. This header can contain either a java.util.Date or long with the timestamp. If the timestamp exists and the option is enabled it will set this timestamp on the written file. Note: This option only applies to the file producer. You cannot use this option with any of the ftp producers. http://git-wip-us.apache.org/repos/asf/camel/blob/27ed9cb4/components/camel-ftp/src/main/docs/ftps-component.adoc ---------------------------------------------------------------------- diff --git a/components/camel-ftp/src/main/docs/ftps-component.adoc b/components/camel-ftp/src/main/docs/ftps-component.adoc index 8929d77..333b09a 100644 --- a/components/camel-ftp/src/main/docs/ftps-component.adoc +++ b/components/camel-ftp/src/main/docs/ftps-component.adoc @@ -32,7 +32,7 @@ The FTPS component has no options. // endpoint options: START -The FTPS component supports 112 endpoint options which are listed below: +The FTPS component supports 113 endpoint options which are listed below: {% raw %} [width="100%",cols="2,1,1m,1m,5",options="header"] @@ -76,6 +76,7 @@ The FTPS component supports 112 endpoint options which are listed below: | tempFileName | producer | | String | The same as tempPrefix option but offering a more fine grained control on the naming of the temporary filename as it uses the File Language. | tempPrefix | producer | | String | This option is used to write the file using a temporary name and then after the write is complete rename it to the real name. Can be used to identify files being written and also avoid consumers (not using exclusive read locks) reading in progress files. Is often used by FTP when uploading big files. | allowNullBody | producer (advanced) | false | boolean | Used to specify if a null body is allowed during file writing. If set to true then an empty file will be created when set to false and attempting to send a null body to the file component a GenericFileWriteException of 'Cannot write null body to file.' will be thrown. If the fileExist option is set to 'Override' then the file will be truncated and if set to append the file will remain unchanged. +| chmod | producer (advanced) | | String | Allows you to set chmod on the stored file. For example chmod=640. | disconnectOnBatchComplete | producer (advanced) | false | boolean | Whether or not to disconnect from remote FTP server right after a Batch upload is complete. disconnectOnBatchComplete will only disconnect the current connection to the FTP server. | eagerDeleteTargetFile | producer (advanced) | true | boolean | Whether or not to eagerly delete any existing target file. This option only applies when you use fileExists=Override and the tempFileName option as well. You can use this to disable (set it to false) deleting the target file before the temp file is written. For example you may write big files and want the target file to exists during the temp file is being written. This ensure the target file is only deleted until the very last moment just before the temp file is being renamed to the target filename. This option is also used to control whether to delete any existing files when fileExist=Move is enabled and an existing file exists. If this option copyAndDeleteOnRenameFails false then an exception will be thrown if an existing file existed if its true then the existing file is deleted before the move operation. | keepLastModified | producer (advanced) | false | boolean | Will keep the last modified timestamp from the source file (if any). Will use the Exchange.FILE_LAST_MODIFIED header to located the timestamp. This header can contain either a java.util.Date or long with the timestamp. If the timestamp exists and the option is enabled it will set this timestamp on the written file. Note: This option only applies to the file producer. You cannot use this option with any of the ftp producers. http://git-wip-us.apache.org/repos/asf/camel/blob/27ed9cb4/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConfiguration.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConfiguration.java index 876f027..f8492f0 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConfiguration.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConfiguration.java @@ -33,6 +33,8 @@ public class FtpConfiguration extends RemoteFileConfiguration { private String account; @UriParam(label = "advanced") private String activePortRange; + @UriParam(label = "producer,advanced") + private String chmod; public FtpConfiguration() { setProtocol("ftp"); @@ -70,4 +72,15 @@ public class FtpConfiguration extends RemoteFileConfiguration { public void setActivePortRange(String activePortRange) { this.activePortRange = activePortRange; } + + /** + * Allows you to set chmod on the stored file. For example chmod=640. + */ + public void setChmod(String chmod) { + this.chmod = chmod; + } + + public String getChmod() { + return chmod; + } } http://git-wip-us.apache.org/repos/asf/camel/blob/27ed9cb4/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java ---------------------------------------------------------------------- diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java index f2447ff..e0af7fc 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java @@ -593,7 +593,17 @@ public class FtpOperations implements RemoteFileOperations<FTPFile> { log.debug("Took {} ({} millis) to store file: {} and FTP client returned: {}", new Object[]{TimeUtils.printDuration(watch.taken()), watch.taken(), targetName, answer}); } - + + // after storing file, we may set chmod on the file + String chmod = ((FtpConfiguration) endpoint.getConfiguration()).getChmod(); + if (ObjectHelper.isNotEmpty(chmod)) { + log.debug("Setting chmod: {} on file: {}", chmod, targetName); + String command = "chmod " + chmod + " " + targetName; + log.trace("Client sendSiteCommand: {}", command); + boolean success = client.sendSiteCommand(command); + log.trace("Client sendSiteCommand successful: {}", success); + } + // store client reply information after the operation exchange.getIn().setHeader(FtpConstants.FTP_REPLY_CODE, client.getReplyCode()); exchange.getIn().setHeader(FtpConstants.FTP_REPLY_STRING, client.getReplyString()); http://git-wip-us.apache.org/repos/asf/camel/blob/27ed9cb4/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpWithChmodTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpWithChmodTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpWithChmodTest.java new file mode 100644 index 0000000..446254a --- /dev/null +++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpWithChmodTest.java @@ -0,0 +1,36 @@ +/* + * Copyright (c): it@M - Dienstleister für Informations- und Telekommunikationstechnik + * der Landeshauptstadt München, 2016 + */ +package org.apache.camel.component.file.remote; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; + +/** + * @author eidottermihi + */ +public class FromFileToFtpWithChmodTest extends FtpServerTestSupport { + + protected String getFtpUrl() { + return "ftp://admin@localhost:" + getPort() + "/tmp2/camel?password=admin&consumer.initialDelay=3000&chmod=777"; + } + + @Test + public void testFromFileToFtp() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(1); + + assertMockEndpointsSatisfied(); + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from(getFtpUrl()).to("mock:result"); + from("file:src/main/data?noop=true&consumer.delay=3000").to(getFtpUrl()); + } + }; + } +}