This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 89f16b3  CAMEL-14947 check for existance of remote directory using ls 
very slow (#3776)
89f16b3 is described below

commit 89f16b301dc3c07803c560e2cd76d8319a3904c9
Author: Chandrakant Hardahe <[email protected]>
AuthorDate: Sat Apr 25 11:41:59 2020 +0530

    CAMEL-14947 check for existance of remote directory using ls very slow 
(#3776)
    
    Co-authored-by: Chandrakant Hardahe <[email protected]>
---
 .../component/file/remote/RemoteFileEndpoint.java  | 22 ++++++++++++++++++++++
 .../component/file/remote/SftpOperations.java      |  6 +++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
index 273f6c6..1b3ef22 100644
--- 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
+++ 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
@@ -62,6 +62,13 @@ public abstract class RemoteFileEndpoint<T> extends 
GenericFileEndpoint<T> {
                                                          + "option is set to 
false, then the message body will be null, but the consumer will still trigger 
a Camel "
                                                          + "Exchange that has 
details about the file such as file name, file size, etc. It's just that the 
file will "
                                                          + "not be 
downloaded.")
+
+    private boolean  loadFullDirectory;
+    @UriParam(label = "advanced", description = " If set this option to be 
true, camel-ftp will load the full directory listing and load it over the wire."
+                                                + "If the remote directory has 
a lot of files then this option can be set to false, camel-ftp will use the "
+                                                + "old way to check if 
directory exist via cd. This can be used to speed up the process If the remote"
+                                                + " directory has a lot of 
files.", defaultValue = "false")
+
     private boolean download = true;
 
     public RemoteFileEndpoint() {
@@ -309,4 +316,19 @@ public abstract class RemoteFileEndpoint<T> extends 
GenericFileEndpoint<T> {
     public void setDownload(boolean download) {
         this.download = download;
     }
+
+    public boolean isLoadFullDirectory() {
+        return  loadFullDirectory;
+    }
+
+    /**
+     * If set this option to be true, camel-ftp will load the full directory 
listing and load it over the wire.
+     * If the remote directory has a lot of files then this option can be set 
to false, camel-ftp will use the
+     * old way to check if directory exist via cd. This can be used to speed 
up the process If the remote"
+     * directory has a lot of files.
+     */
+    public void setLoadFullDirectory(boolean loadFullDirectory) {
+        this.loadFullDirectory = loadFullDirectory;
+    }
+
 }
diff --git 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
index 6203e2f..7bd4130 100644
--- 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
+++ 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
@@ -517,7 +517,11 @@ public class SftpOperations implements 
RemoteFileOperations<SftpRemoteFile> {
         try {
             // maybe the full directory already exists
             try {
-                channel.ls(directory);
+                if (this.endpoint.isLoadFullDirectory()) {
+                    channel.ls(directory);
+                } else {
+                    channel.cd(directory);
+                }
                 success = true;
             } catch (SftpException e) {
                 // ignore, we could not change directory so try to create it

Reply via email to