Search code examples
androidjcifs

Slow file listing with jCIFS on Windows


jCIFS is a great library for connecting to SMB shares on Android, and it works excellently with almost all setups I've tested with.

I do, however, experience incredibly slow performance when using the SmbFile.listFiles() method on Windows-based network shares, but only when logging in as an actual user on the PC. It can take up to several minutes to simply get a list of folders, and sometimes nothing happens at all.

If I choose to log in as a guest (by using "guest" as user, and leaving the password empty), everything is fast. Usually less than a second.

The following code works and it's fast:

try {
   NtlmPasswordAuthentication authentication = new NtlmPasswordAuthentication("", "guest", ""); // domain, user, password
   currentFolder = new SmbFile("smb://host-name-for-my-pc", authentication);
   SmbFile[] listFiles = currentFolder.listFiles();
} catch (Exception e) { // Using Exception for the sake of demonstration...

This code, however, doesn't work / is very slow:

try {
   NtlmPasswordAuthentication authentication = new NtlmPasswordAuthentication("", "my-username", "my-password"); // domain, user, password
   currentFolder = new SmbFile("smb://host-name-for-my-pc", authentication);
   SmbFile[] listFiles = currentFolder.listFiles();
} catch (Exception e) { // Using Exception for the sake of demonstration...

I spoke to another guy, who's using jCIFS, and he is experiencing the same problem.

I've tried connecting to the same share using ES File Explorer, which also utilizes jCIFS, and it's fast regardless of using a real account or logging in as a guest.

Update:

If I use SmbFile("username:password@server/") instead, it works! I really want it to work with NtlmPasswordAuthentication, though. Any ideas?


Solution

  • Using new SmbFile("username:password@server/") works, so I'm just using that.