Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
15.5k views
in Java FTP by
hi:
I am a software engineer from China and I have just downloaded the latest version :edtFTPj-2.0.4.
It seems that the method uploadFile(localFileName, remoteFileName) in class FileTransferClient does not work if the parameter "remoteFileName" contains Simplified Chinese Characters,such as uploadFile("C:/demo.wmv", "哈哈.wmv").
Before invoking the uploadFile method I have invoked method getAdvancedSettings().setControlEncoding("GBK2312") as the API says.
Here below are my codes:
FileTransferClient ftp = new FileTransferClient();
try{
    ftp.setRemoteHost("192.168.1.101");
    ftp.setUserName("admin");
    ftp.setPassword("admin");
    ftp.connect();
    ftp.getAdvancedSettings().setControlEncoding("GBK2312");
   String localPath = "F:/";
   String localFileName = "Kings.without.crown.by.magiconeal.wmv";
   ftp.setContentType(FTPTransferType.BINARY);
   System.out.println("上传开始时间:"+ new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.ssssss").format(new Date()));
   System.out.println("文件大小:"+new File(localPath+localFileName).length()/(1024*1024)+"MB");
   ftp.uploadFile(localPath+localFileName, "中文演示.wmv");
  System.out.println("上传结束时间:"+ new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.ssssss").format(new Date()));

and the stack trace are below:
enterprisedt.net.ftp.FTPException: 550 /????.wmv: Cannot create file.
at enterprisedt.net.ftp.FTPControlSocket.validateReply(FTPControlSocket.java:1128)
at enterprisedt.net.ftp.FTPClient.initPut(FTPClient.java:2518)
at enterprisedt.net.ftp.FTPClient.putData(FTPClient.java:2577)
at enterprisedt.net.ftp.FTPClient.putStream(FTPClient.java:2310)
at enterprisedt.net.ftp.FTPClient.put(FTPClient.java:2195)
at enterprisedt.net.ftp.FTPClient.put(FTPClient.java:2281)
at enterprisedt.net.ftp.FileTransferClient.uploadFile(FileTransferClient.java:669)
at enterprisedt.net.ftp.FileTransferClient.uploadFile(FileTransferClient.java:643)
at demo.Edtftpj_FTPTransferClient.main(Edtftpj_FTPTransferClient.java:27)

By the way,I have just made anothoer demo using class FTPClient, it works fine with Simplified Chinese after I invoke FTPClient.setControlEncoding("GBK2312").
Thanks a lot !

13 Answers

0 votes
by
Hi
I have fixed the problem temporarily by replacing DEFAULT_ENCODING in class FTPClinet with "GBK",while its original value is "US-ASCII".But I want to know if there is another way to solve this problem,or fix this bug。
Thanks
0 votes
by (162k points)
So in summary, it works for FTPClient but not for FileTransferClient?
0 votes
by
That's it ! It only works after I change DEFAULT_ENCODING in Class FTPClient,using "GBK" instead of "US-ASCII". It does't work even if I have invoked FileTransferClient.getAdvancedSettings().setControlEncoding("GBK2312") before uploading
0 votes
by (162k points)
Must be a bug, we'll take a look.
0 votes
by (162k points)
Please note, you must set the control encoding *before* you connect to the server.

It is too late to change the encoding once the connection is established.

I've looked at the code and there doesn't seem to be a problem there.

FileTransferClient.getAdvancedSettings().setControlEncoding("GBK")

should work (if GBK is what you want).
0 votes
by
ok,I will check it.
Thanks a lot.
0 votes
by (520 points)
when i set ftpclient.setControlEncoding("GBK2312"),
this is what i get


java.io.UnsupportedEncodingException: GBK2312
at sun.io.Converters.getConverterClass(Converters.java:218)
at sun.io.Converters.newConverter(Converters.java:251)
at sun.io.ByteToCharConverter.getConverter(ByteToCharConverter.java:68)
at sun.nio.cs.StreamDecoder$ConverterSD.<init>(StreamDecoder.java:224)
at sun.nio.cs.StreamDecoder$ConverterSD.<init>(StreamDecoder.java:210)
at sun.nio.cs.StreamDecoder.forInputStreamReader(StreamDecoder.java:77)
at java.io.InputStreamReader.<init>(InputStreamReader.java:83)
at com.enterprisedt.net.ftp.FTPControlSocket.initStreams(FTPControlSocket.java:432)
at com.enterprisedt.net.ftp.FTPControlSocket.<init>(FTPControlSocket.java:383)
at com.enterprisedt.net.ftp.FTPControlSocket.<init>(FTPControlSocket.java:355)
at com.enterprisedt.net.ftp.FTPClient.connect(FTPClient.java:958)
at com.adventnet.fa.server.imp.FTPUtil.getFTPClient(FTPUtil.java:41)
at Ftw.main(Ftw.java:20)
0 votes
by (162k points)
Have you tried Big5?
0 votes
by (520 points)
yes i tried sir
0 votes
by (162k points)
If an encoding you want is not supported by Java there's not much we can do about it.

Categories

...