camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1002541 - /camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
Date Wed, 29 Sep 2010 09:45:45 GMT
Author: davsclaus
Date: Wed Sep 29 09:45:45 2010
New Revision: 1002541

URL: http://svn.apache.org/viewvc?rev=1002541&view=rev
Log:
CAMEL-3174: sftp retrieve file should change dir when doing that.

Modified:
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java?rev=1002541&r1=1002540&r2=1002541&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
(original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
Wed Sep 29 09:45:45 2010
@@ -397,7 +397,23 @@ public class SftpOperations implements R
                     (GenericFile<ChannelSftp.LsEntry>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
             ObjectHelper.notNull(target, "Exchange should have the " + FileComponent.FILE_EXCHANGE_FILE
+ " set");
             target.setBody(os);
-            channel.get(name, os);
+
+            // remember current directory
+            String currentDir = getCurrentDirectory();
+
+            // change directory to path where the file is to be retrieved
+            // (must do this as some FTP servers cannot retrieve using absolute path)
+            String path = FileUtil.onlyPath(name);
+            if (path != null) {
+                changeCurrentDirectory(path);
+            }
+            String onlyName = FileUtil.stripPath(name);
+
+            channel.get(onlyName, os);
+
+            // change back to current directory
+            changeCurrentDirectory(currentDir);
+
             return true;
         } catch (SftpException e) {
             throw new GenericFileOperationFailedException("Cannot retrieve file: " + name,
e);
@@ -450,11 +466,26 @@ public class SftpOperations implements R
             throw new GenericFileOperationFailedException("Cannot create new local work file:
" + local);
         }
 
-
         try {
             // store the java.io.File handle as the body
             file.setBody(local);
-            channel.get(name, os);
+
+            // remember current directory
+            String currentDir = getCurrentDirectory();
+
+            // change directory to path where the file is to be retrieved
+            // (must do this as some FTP servers cannot retrieve using absolute path)
+            String path = FileUtil.onlyPath(name);
+            if (path != null) {
+                changeCurrentDirectory(path);
+            }
+            String onlyName = FileUtil.stripPath(name);
+
+            channel.get(onlyName, os);
+
+            // change back to current directory
+            changeCurrentDirectory(currentDir);
+
         } catch (SftpException e) {
             if (LOG.isTraceEnabled()) {
                 LOG.trace("Error occurred during retrieving file: " + name + " to local directory.
Deleting local work file: " + temp);



Mime
View raw message