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", "[EMAIL PROTECTED]");
// 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:[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]