I am using Apache FTPClient for getting files and sub-directory files listing. But it cant get listing of files from directory name with spaces. Here is an example - I tried it with two different directories:
FTPClient client = new org.apache.commons.net.ftp.FTPClient();
client.connect("ftp.domain.com");
client.login("userid", "password");
FTPFile[] names = client.listDirectories("ABC XYZ"); //Empty array
FTPFile[] names2 = client.listDirectories("ABCXYZ"); //working
So directory name with spaces not returning anything. I tried to put "%20" and "+" at the place of space. Also I tried "\"ABC XYZ\"". But still is not working. Am I missing anything.
This is an old one, but I recently ran into this problem and found a solution that seems to work for me. Use the escape character "\" to escape your spaces.
So for instance:
String path = "/Path/To/Folder With/Spaces";
path = path.replace(" ", "\\ ");
FTPFile[] listedDirectories = client.listDirectories(path);