try using FTPClientConfig to specify the language. Refer the API here - http://commons.apache.org/net/api-3.1/org/apache/commons/net/ftp/FTPClientConfig.html
Indu On 13 June 2012 16:00, Susanta Mohapatra <[email protected]>wrote: > Hello everyone, > > I am not able to fetch filenames with german characters using FTPClient. > > Here is the sample code: > > private static void testFTP(String host, String pathname, String resource) > { > boolean error = false; > FTPClient ftp = null; > try { > int reply; > ftp = new FTPClient(); > ftp.connect(host); > ftp.setControlEncoding("UTF-8"); > ftp.setAutodetectUTF8(true); > > ftp.login("xxxxx", "xxxxx"); > System.out.println("Connected to " + host + "."); > System.out.print(ftp.getReplyString()); > > // After connection attempt, you should check the reply code to verify > // success. > reply = ftp.getReplyCode(); > > if(!FTPReply.isPositiveCompletion(reply)) { > ftp.disconnect(); > System.err.println("FTP server refused connection."); > System.exit(1); > } > boolean ok = ftp.changeWorkingDirectory(pathname); > System.out.println("Change dir ok: " + ok) ; > > FTPFile[] files = ftp.listFiles(); > if(files != null) { > for(FTPFile f : files) { > System.out.println("file: " + f.getName()); > if(f.getName().equals(resource)) { > System.out.println("Resouce found: " + resource); > } > > } > } > > InputStream is = ftp.retrieveFileStream(resource); > reply = ftp.getReplyCode(); > System.out.print("Stream1 status: " + ftp.getReplyString()); > System.out.println("Stream: " + is); > > InputStream is1 = ftp.retrieveFileStream("rssfeed1.xml"); > System.out.print("Stream2 status: " + ftp.getReplyString()); > System.out.println("Stream: " + is1); > if(is != null) > is.close(); > if(is1 != null) > is1.close(); > // transfer files > ftp.logout(); > } catch(IOException e) { > error = true; > e.printStackTrace(); > } finally { > if(ftp.isConnected()) { > try { > ftp.disconnect(); > } catch(IOException ioe) { > // do nothing > } > } > System.exit(error ? 1 : 0); > } > } > > > I am invoking this method as: > > testFTP("xxxxxx", "dir", "sozial-fähigen-Anwendungen.txt"); > > The program runs with positive match for resource name in the list command. > But fails to return stream for the above file name, wheras the other file > returns stream. > > This is the output: > > Connected to xxxxxx > 230 Login successful. > Change dir ok: true > file: rssfeed1.xml > file: sozial-fähigen-Anwendungen.txt > Resource found: "sozial-fähigen-Anwendungen.txt" > Stream1 status: 550 Failed to open file. > Stream: null > Stream2 status: 150 Opening BINARY mode data connection for rssfeed1.xml > (8035 bytes). > Stream: org.apache.commons.net.io.SocketInputStream@1632847 > > Any help for this matter is highly appreciated. > > Thanks > Susanta >
