commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dima Retov <d...@axisway.com>
Subject Re[2]: FTP and Russian file name
Date Wed, 13 Jun 2007 08:13:13 GMT
Thanks. I was looking for content type in configure and missed it.

But it still does not work. I still able to open file but I can't
download it. (FTP reports 550 file not found)

Other program can do that.

Is it possible that non-ascii characters should be encoded
additionally?

Regards,
Dima

Wednesday, June 13, 2007, 12:01:11 AM, you wrote:

RW> Hi Dima

RW> Have you tried calling FTP::setControlEncoding() with the appropriate
RW> encoding scheme?

RW> e.g.

RW> ftpClient.setControlEncoding("UTF-8")

RW> Regards
RW> Rory

RW> Dima Retov wrote:
>> Hello,
>>
>> I am failing to download files from server that has russian folders
>> and files using FTPClient from Commons-Net.
>>
>> I am able to do that with firefox and IE.
>>
>> Here is my code.
>>
>>
>>     try{
>>         FTPClient ftp = new FTPClient();
>>         ftp.connect("ftp.server");
>>         ftp.enterLocalPassiveMode();
>>         ftp.login("anonymous", "a@a.com");
>>
>>
>>
>>         // Convert Unicode to Windows-1251 charset
>>         byte[] buf = "Русская Папка/Папка 2/".getBytes("windows-1251");
>>         String s2 = new String(buf, 0);
>>
>>
>>         // FTPClient opens that folder
>>         ftp.changeWorkingDirectory(s2);
>>         
>>         
>>         FTPFile[] list = ftp.listFiles();
>>         
>>         for(FTPFile file : list){
>>             if(file.isFile()){
>>
>>             
>>                 String s = file.getName();
>>
>>
>>                 // Decode russian to Unicode
>>                 
>>                 byte[] buf1 = new byte[s.length()];
>>                 for(int i = 0; i < buf1.length; i++){
>>                     buf1[i] = (byte)s.charAt(i);
>>                 }
>>                 String s1 = new String(buf1, "windows-1251");
>>
>>                 // s1 is correctly decoded
>>
>>                 java.io.File localFile = new java.io.File(s1);
>>                 if(localFile.exists()){
>>                     ftp.setRestartOffset(localFile.length());
>>                 }
>>                 OutputStream os = new
>> FileOutputStream(localFile.getAbsolutePath(), true);
>>
>>
>>                 // retrieveFileStream - returns null for files with
>>                 // russian letters. (s = file.getName())
>>                 
>>                 InputStream is = ftp.retrieveFileStream(s);
>>
>>                 // ftp.getReplyString() return ~ error 550 ... file not found
>>                 
>>                 String s3 = ftp.getReplyString();
>>                 org.apache.commons.net.io.Util.copyStream(is, os);
>>                 is.close();
>>                 os.close();
>>             }
>>         }
>>         ftp.disconnect();
>>         
>>     } catch(Exception ex){
>>         System.out.println(ex);
>>     }
>>
>>
>> So I can change folder with Russian name but can't download file with
>> Russian name.
>>
>>
>> Please, help if you have solution how to fix it.
>>
>>
>>
>> --
>> Best regards,
>>  Dima                          mailto:dima@axisway.com
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail:
>> commons-user-help@jakarta.apache.org
>>
>>
>>
>>
>>   



RW> ---------------------------------------------------------------------
RW> To unsubscribe, e-mail:
RW> commons-user-unsubscribe@jakarta.apache.org
RW> For additional commands, e-mail:
RW> commons-user-help@jakarta.apache.org




-- 
Best regards,
 Dima                            mailto:dima@axisway.com



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message