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