You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2013/09/23 20:14:47 UTC

svn commit: r1525663 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs2/ core/src/main/java/org/apache/commons/vfs2/provider/sftp/ src/changes/

Author: ggregory
Date: Mon Sep 23 18:14:47 2013
New Revision: 1525663

URL: http://svn.apache.org/r1525663
Log:
[VFS-494][SFTP] No support for SFTP servers with non Latin-1 file name encoding. The provided patch did not apply cleanly, this version should be equivalent.

Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties?rev=1525663&r1=1525662&r2=1525663&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties Mon Sep 23 18:14:47 2013
@@ -244,6 +244,7 @@ vfs.provider.sftp/config-sshdir.error=SS
 vfs.provider.sftp/connect.error=Could not connect to SFTP server at "{0}".
 vfs.provider.sftp/create-folder.error=Folder creation failed with unknown error.
 vfs.provider.sftp/delete.error=Delete failed with unknown error.
+vfs.provider.sftp/filename-encoding.error=Could not change to file name encoding "{0}"
 vfs.provider.sftp/get-file.error=Read file contents failed with unknown error.
 vfs.provider.sftp/known-hosts.error=Error during processing known-hosts file "{0}".
 vfs.provider.sftp/list-children.error=List folder contents failed with unknown error.

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java?rev=1525663&r1=1525662&r2=1525663&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java Mon Sep 23 18:14:47 2013
@@ -126,7 +126,18 @@ public class SftpFileSystem
                     }
                 }
             }
-            return channel;
+
+            String fileNameEncoding = SftpFileSystemConfigBuilder.getInstance().getFileNameEncoding(
+                    getFileSystemOptions());
+
+            if (fileNameEncoding != null) {
+                try {
+                    channel.setFilenameEncoding(fileNameEncoding);
+                } catch (SftpException e) {
+                    throw new FileSystemException("vfs.provider.sftp/filename-encoding.error", fileNameEncoding);
+                }
+            }
+			return channel;
         }
         catch (final JSchException e)
         {

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java?rev=1525663&r1=1525662&r2=1525663&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java Mon Sep 23 18:14:47 2013
@@ -135,7 +135,8 @@ public final class SftpFileSystemConfigB
     private static final String STRICT_HOST_KEY_CHECKING = _PREFIX + ".STRICT_HOST_KEY_CHECKING";
     private static final String TIMEOUT = _PREFIX + ".TIMEOUT";
     private static final String USER_DIR_IS_ROOT = _PREFIX + ".USER_DIR_IS_ROOT";
-
+    private static final String ENCODING = _PREFIX + ".ENCODING";
+    
     /**
      * Gets the singleton builder.
      *
@@ -169,6 +170,18 @@ public final class SftpFileSystemConfigB
     }
 
     /**
+     * Gets the file name encoding.
+     * 
+     * @param opts
+     *            The FileSystem options.
+     * @return the file name encoding
+     */
+    public String getFileNameEncoding(FileSystemOptions opts) 
+    {
+        return this.getString(opts, ENCODING);
+    }
+
+    /**
      * Gets the identity files (your private key files).
      * <p>
      * We use java.io.File because JSch cannot deal with VFS FileObjects.
@@ -231,6 +244,7 @@ public final class SftpFileSystemConfigB
         return (File) this.getParam(opts, KNOWN_HOSTS);
     }
 
+
     /**
      * Gets authentication order.
      *
@@ -244,19 +258,21 @@ public final class SftpFileSystemConfigB
         return getString(opts, PREFERRED_AUTHENTICATIONS);
     }
 
-
     /**
-     * Gets the user name for the proxy used for the SFTP connection.
+     * Gets the command that will be run on the proxy
+     * host when using a {@linkplain SftpStreamProxy}. The
+     * command defaults to {@linkplain SftpStreamProxy#NETCAT_COMMAND}.
      *
      * @param opts
      *            The FileSystem options.
-     * @return proxyUser
-     * @see #setProxyUser
+     * @return proxyOptions
+     * @see SftpStreamProxy
+     * @see #setProxyOptions
      * @since 2.1
      */
-    public String getProxyUser(final FileSystemOptions opts)
+    public String getProxyCommand(final FileSystemOptions opts)
     {
-        return this.getString(opts, PROXY_USER);
+        return this.getString(opts, PROXY_COMMAND, SftpStreamProxy.NETCAT_COMMAND);
     }
 
     /**
@@ -274,20 +290,6 @@ public final class SftpFileSystemConfigB
     }
 
     /**
-     * Gets the proxy-port to use for the SFTP the connection You have to set the ProxyHost too if you would like to
-     * have the proxy really used.
-     * 
-     * @param opts
-     *            The FileSystem options.
-     * @return proxyPort: the port number or 0 if it is not set
-     * @see #setProxyHost
-     */
-    public int getProxyPort(final FileSystemOptions opts)
-    {
-        return this.getInteger(opts, PROXY_PORT, 0);
-    }
-
-    /**
      * Gets the proxy options that are used to connect
      * to the proxy host.
      *
@@ -320,20 +322,17 @@ public final class SftpFileSystemConfigB
     }
 
     /**
-     * Gets the command that will be run on the proxy
-     * host when using a {@linkplain SftpStreamProxy}. The
-     * command defaults to {@linkplain SftpStreamProxy#NETCAT_COMMAND}.
-     *
+     * Gets the proxy-port to use for the SFTP the connection You have to set the ProxyHost too if you would like to
+     * have the proxy really used.
+     * 
      * @param opts
      *            The FileSystem options.
-     * @return proxyOptions
-     * @see SftpStreamProxy
-     * @see #setProxyOptions
-     * @since 2.1
+     * @return proxyPort: the port number or 0 if it is not set
+     * @see #setProxyHost
      */
-    public String getProxyCommand(final FileSystemOptions opts)
+    public int getProxyPort(final FileSystemOptions opts)
     {
-        return this.getString(opts, PROXY_COMMAND, SftpStreamProxy.NETCAT_COMMAND);
+        return this.getInteger(opts, PROXY_PORT, 0);
     }
 
     /**
@@ -349,6 +348,20 @@ public final class SftpFileSystemConfigB
     }
 
     /**
+     * Gets the user name for the proxy used for the SFTP connection.
+     *
+     * @param opts
+     *            The FileSystem options.
+     * @return proxyUser
+     * @see #setProxyUser
+     * @since 2.1
+     */
+    public String getProxyUser(final FileSystemOptions opts)
+    {
+        return this.getString(opts, PROXY_USER);
+    }
+
+    /**
      * @param opts
      *            The FileSystem options.
      * @return the option value The host key checking.
@@ -418,6 +431,18 @@ public final class SftpFileSystemConfigB
     }
 
     /**
+     * Sets the file name encoding.
+     * 
+     * @param opts
+     *            The FileSystem options.
+     * @param fileNameEncoding
+     */
+    public void setFileNameEncoding(FileSystemOptions opts, String fileNameEncoding) 
+    {
+        this.setParam(opts, ENCODING, fileNameEncoding);
+    }
+
+    /**
      * Sets the identity files (your private key files).
      * <p>
      * We use java.io.File because JSch cannot deal with VFS FileObjects.
@@ -509,6 +534,21 @@ public final class SftpFileSystemConfigB
     }
 
     /**
+     * Sets the proxy username to use for the SFTP connection.
+     *
+     * @param opts
+     *            The FileSystem options.
+     * @param proxyCommand
+     *            the port
+     * @see #getProxyOptions
+     * @since 2.1
+     */
+    public void setProxyCommand(final FileSystemOptions opts, final String proxyCommand)
+    {
+        this.setParam(opts, PROXY_COMMAND, proxyCommand);
+    }
+
+    /**
      * Sets the proxy to use for the SFTP connection.
      *
      * You MUST also set the ProxyPort to use the proxy.
@@ -524,6 +564,39 @@ public final class SftpFileSystemConfigB
         this.setParam(opts, PROXY_HOST, proxyHost);
     }
 
+
+    /**
+     * Sets the proxy username to use for the SFTP connection.
+     *
+     * @param opts
+     *            The FileSystem options.
+     * @param proxyOptions
+     *            the options
+     * @see #getProxyOptions
+     * @since 2.1
+     */
+    public void setProxyOptions(final FileSystemOptions opts, final FileSystemOptions proxyOptions)
+    {
+        this.setParam(opts, PROXY_OPTIONS, proxyOptions);
+    }
+
+
+
+    /**
+     * Sets the proxy password to use for the SFTP connection.
+     *
+     * @param opts
+     *            The FileSystem options.
+     * @param proxyPassword
+     *            the username used to connect to the proxy
+     * @see #getProxyPassword
+     * @since 2.1
+     */
+    public void setProxyPassword(final FileSystemOptions opts, final String proxyPassword)
+    {
+        this.setParam(opts, PROXY_PASSWORD, proxyPassword);
+    }
+
     /**
      * Sets the proxy port to use for the SFTP connection.
      *
@@ -575,54 +648,6 @@ public final class SftpFileSystemConfigB
         this.setParam(opts, PROXY_USER, proxyUser);
     }
 
-
-    /**
-     * Sets the proxy password to use for the SFTP connection.
-     *
-     * @param opts
-     *            The FileSystem options.
-     * @param proxyPassword
-     *            the username used to connect to the proxy
-     * @see #getProxyPassword
-     * @since 2.1
-     */
-    public void setProxyPassword(final FileSystemOptions opts, final String proxyPassword)
-    {
-        this.setParam(opts, PROXY_PASSWORD, proxyPassword);
-    }
-
-
-
-    /**
-     * Sets the proxy username to use for the SFTP connection.
-     *
-     * @param opts
-     *            The FileSystem options.
-     * @param proxyOptions
-     *            the options
-     * @see #getProxyOptions
-     * @since 2.1
-     */
-    public void setProxyOptions(final FileSystemOptions opts, final FileSystemOptions proxyOptions)
-    {
-        this.setParam(opts, PROXY_OPTIONS, proxyOptions);
-    }
-
-    /**
-     * Sets the proxy username to use for the SFTP connection.
-     *
-     * @param opts
-     *            The FileSystem options.
-     * @param proxyCommand
-     *            the port
-     * @see #getProxyOptions
-     * @since 2.1
-     */
-    public void setProxyCommand(final FileSystemOptions opts, final String proxyCommand)
-    {
-        this.setParam(opts, PROXY_COMMAND, proxyCommand);
-    }
-
     /**
      * Configures the host key checking to use.
      * <p>
@@ -664,7 +689,8 @@ public final class SftpFileSystemConfigB
     {
         this.setParam(opts, TIMEOUT, timeout);
     }
-
+    
+    
     /**
      * Sets the whether to use the user directory as root (do not change to file system root).
      *

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1525663&r1=1525662&r2=1525663&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Mon Sep 23 18:14:47 2013
@@ -26,8 +26,11 @@
 <!--       <action issue="VFS-443" dev="ggregory" type="update" due-to="nickallen"> -->
 <!--     	[Local] Need an easy way to convert from a FileObject to a File. -->
 <!--       </action> -->
+      <action issue="VFS-494" dev="ggregory" type="update" due-to="Allen Xudong Cheng">
+        [SFTP] No support for SFTP servers with non Latin-1 file name encoding.
+      </action>
       <action issue="VFS-368" dev="ggregory" type="update" due-to="Brendan Long">
-        SFTP documentation implies that "userDirIsRoot" defaults to true.
+        [SFTP] Documentation implies that "userDirIsRoot" defaults to true.
       </action>
       <action issue="VFS-265" dev="ggregory" type="update" due-to="Scott Bjerstedt">
         [FTP] Set user dir as root dir by default.