commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geoff Watters <geoff.watt...@oracle.com>
Subject Re: [vfs] vsf2.2.0: non-ascii chars in file name are not handled by createFolder()
Date Wed, 15 Apr 2015 14:55:28 GMT
Albert
Thanks so much for your suggestion. In my environment, I tried to make 
the changes you suggested, however the

    *org.apache.commons.net.ftp.FtpClient*

class in my environment does not support *setAutodetectUTF8(boolean)*.

Instead, I changed my version of *FtpClientFactory *so that 
*setControlEncoding()* is invoked before the connection is made, see 
green block below.

    76           FTPFileEntryParserFactory myFactory =
    77
    FtpFileSystemConfigBuilder.getInstance().getEntryParserFactory(fileSystemOptions);
    78            if (myFactory != null)
    79            {
    80                client.setParserFactory(myFactory);
    81            }
    82
    83            try
    84            {
    85                String controlEncoding =
    FtpFileSystemConfigBuilder.getInstance().getControlEncoding(fileSystemOptions);
    86                if (controlEncoding != null)
    87                {
    88 client.setControlEncoding(controlEncoding);
    89                }
    90                client.connect(hostname, port);
    91
    92                int reply = client.getReplyCode();

After building *commons-vfs2-2.0.jar*, the above change allowed my 
testcase to pass and I was able to see the correct file names on my 
target system.

I note that the javadoc for FtpClient.setAutodetectUTF8() 
<https://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClient.html#setAutodetectUTF8%28boolean%29>

does mention that it should be "/invoked before a connection is 
established/". Perhaps the same is true 
fororg.apache.commons.net.ftp.Ftp.setControlEncoding() 
<https://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTP.html#setControlEncoding%28java.lang.String%29>.

Thanks
Geoff

On 09/04/2015 21:05, Albert Briner wrote:
> Geoff,
>
> Nicely put together test case. I was able to reproduce your outcome closely (different
FTP server).
>
> What made it work for me was the following change to the VFS source:
>
> Index: FtpClientFactory.java
> ===================================================================
> --- FtpClientFactory.java	(revision 1535203)
> +++ FtpClientFactory.java	(working copy)
> @@ -150,7 +150,11 @@
>                       {
>                           client.setControlEncoding(controlEncoding);
>                       }
> -
> +                    else
> +                    {
> +                        client.setAutodetectUTF8(true);
> +                    }
> +
>                       client.connect(hostname, port);
>   
>                       final int reply = client.getReplyCode();
>
>
> … and then not specify any encoding in the test code. I don't know whether this is
the right thing to do in general, but it made all your test cases succeed for me.
>
> Albert
>
>
> On 16/03/2015 11:07, Geoff Watters wrote:
>> All
>>
>> I am using*commons-vfs2-2.0.jar* and am running into problems when
>> file names contain non-ascii characters. According to
>> https://issues.apache.org/jira/browse/VFS-305 this has been
>> fixed/shipped in 2.0. In my environment I am able to create such file
>> names when using ftp on the command-line (Red Hat Enterprise Linux
>> Server release 5.8 (Tikanga)).
>>
>> When I execute the following sample code, I get the output shown below.
>>
>> public class FtpTest {
>>      public static void main(String[] args) throws FileSystemException
>>      {
>>          String host="hhh";
>>          String user = "uuu";
>>          String password = "ppp";
>>          String destDir = "/tmp";
>>          FileSystemOptions opts = new FileSystemOptions();
>> FtpFileSystemConfigBuilder.getInstance().setControlEncoding(opts,
>> "UTF-8");
>>
>>          DefaultFileSystemManager manager = new
>> DefaultFileSystemManager();
>>          manager.addProvider("ftp", new FtpFileProvider());
>>          manager.init();
>>
>>          String root="ftp://"+user+":"+password+"@"+host+destDir;
>>          // Specify a number of directories that should be created
>> under destDir
>>          String[] lRoots = new String[4];
>>          lRoots[0]= root+"/ftpDebug";
>>          lRoots[1]= root+"/ftp\u7684Debug";  // insert a non-ascii char
>>          lRoots[2]= root+"/ftp\u7685Debug";  // insert a different
>> non-ascii char
>>          lRoots[3]= root+"/ftp\u7684Debug";  // insert the same
>> non-ascii char
>>
>>          // Verify the ControlEncoding
>>          System.out.println("ControlEncoding is
>> "+FtpFileSystemConfigBuilder.getInstance().getControlEncoding(opts));
>>
>>          int dirCount=0;
>>          for (String lRoot: lRoots) {
>>              System.out.println(dirCount+") Process directory
>> ["+lRoot+"]");
>>              FileObject newDir = manager.resolveFile(lRoot, opts);
>>              if (!newDir.exists()) {
>>                  try {
>>                      System.out.println(dirCount+") "+lRoot+" ::Dir
>> Does Not Exist so Create It ");
>>                      newDir.createFolder();
>>                      if (newDir.exists())
>>                          System.out.println(dirCount+") "+lRoot+"
>> ::Creation Successful ");
>>                      else
>>                          System.out.println(dirCount+") "+lRoot+"
>> ::Creation Fails ");
>>                  }
>>                  catch (Exception ex) {
>>                      System.out.println(dirCount+") "+lRoot + " raised
>> "+ex);
>>                  }
>>              }
>>              else
>>                  System.out.println(dirCount+") "+lRoot+" ::Dir Already
>> Exists ");
>>              dirCount++;
>>          }
>>      }
>> }
>>
>> The output from running the above is:-
>>
>> ControlEncoding is UTF-8
>> 0) Process directory [ftp://uuu:ppp@hhh/tmp/ftpDebug]
>> 0) ftp://uuu:ppp@hhh/tmp/ftpDebug ::Dir Does Not Exist so Create It
>> 0) ftp://uuu:ppp@hhh/tmp/ftpDebug ::Creation Successful
>> 1) Process directory [ftp://uuu:ppp@hhh/tmp/ftpªDebug]
>> 1) ftp://uuu:ppp@hhh/tmp/ftpªDebug ::Dir Does Not Exist so Create It
>> 1) ftp://uuu:ppp@hhh/tmp/ftpªDebug ::Creation Successful
>> 2) Process directory [ftp://uuu:ppp@hhh/tmp/ftp%Gçš…%@Debug]
>> 2) ftp://uuu:ppp@hhh/tmp/ftp%Gçš…%@Debug ::Dir Does Not Exist so
>> Create It
>> 2) ftp://uuu:ppp@hhh/tmp/ftp%Gçš…%@Debug raised
>> org.apache.commons.vfs2.FileSystemException: Could not create
>> folder "ftp://uuu:***@hhh/tmp/ftp%Gçš…%@Debug".
>> 3) Process directory [ftp://uuu:ppp@hhh/tmp/ftpªDebug]
>> 3) ftp://uuu:ppp@hhh/tmp/ftpªDebug ::Dir Does Not Exist so Create It
>> 3) ftp://uuu:ppp@hhh/tmp/ftpªDebug raised
>> org.apache.commons.vfs2.FileSystemException: Could not create folder
>> "ftp://uuu:***@hhh/tmp/ftpªDebug".
>>
>> After step 1) I see a directory called*/tmp/ftp?Debug*.
>> I think this is causing the subsequent creation problem in step 2) and
>> step 3).
>> When a directory such as "*ftp\u7684Debug*" does exist, then
>> *exists*() returns the correct result of true, but *createFolder*()
>> creates a directory with name "*ftp?Debug*".
>>
>> Thanks in advance
>> Geoff
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message