juergen d
juergen d

Reputation: 204756

Speed up recursively listing FTP files

I have an Android app that lists folders and files of a FTP directory. I use Apache Commons FTP Client. It comes down to this line which I call for every folder

FTPFile[] folderElements = ftpClient.listFiles(folderName);

Works fine but is very time consuming. The whole task (getting all files and folders) takes about a minute. Can I speed that up somehow?

I already tried

ftpClient.setBufferSize(1024000);

Upvotes: 8

Views: 517

Answers (1)

Honwhy Wang
Honwhy Wang

Reputation: 118

my project might be a help. https://github.com/Honwhy/commons-pool-ftp (see ftpcp branch)

FTPCPManager ftpCPManager = new FTPCPManager();
ftpCPManager.setUrl("ftp://127.0.0.1");
ftpCPManager.setUsername("sa");
ftpCPManager.setPassword("sa");
ftpCPManager.setKeepAliveTimeout(1 * 60);

ftpCPManager.setConnectTimeout(1 * 1000);
ftpCPManager.setMaxWait(1 * 1000);

CommonFAOSupport support = new CommonFAOSupport(ftpCPManager);

support.downloadDirectory("/apps/data/ftp/download", 4000, 10, processService); //10 thread

Upvotes: 2

Related Questions