Sending UTF-8 Encoded File Name With FTPClient Class in Apache Commons

04-02-2020

We can use FTPClient class in apache commons library to send UTF-8 encoded file names, such as Turkish, chinese, german etc.

ftpClient = new FTPClient();
String server ="ftp.server.com";
int port = 21;
String user ="test";
String pass ="test";
ftpClient.setControlEncoding("UTF-8");//must be before connect() method

ftpClient.connect(server, port);
ftpClient.login(user, pass);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.sendCommand("OPTS UTF8 ON");//we should send this command

© 2019 All rights reserved. Codesenior.COM