commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rory Winston <rwins...@eircom.net>
Subject Re: FTP and Russian file name
Date Tue, 12 Jun 2007 21:01:11 GMT
Hi Dima

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

e.g.

ftpClient.setControlEncoding("UTF-8")

Regards
Rory

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
>
>
>
>
>   



---------------------------------------------------------------------
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