Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow file listing with jCIFS on Windows

Tags:

android

jcifs

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?

like image 235
Michell Bak Avatar asked Jan 29 '13 23:01

Michell Bak


2 Answers

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

like image 101
Michell Bak Avatar answered Sep 20 '22 12:09

Michell Bak


Try Using below codes before any jCIFS classes are instantiated:

jcifs.Config.setProperty("resolveOrder", "DNS");

Thanks to Glenn's answer in JCIFS: file retrieval is too slow to be usable

Ref: https://jcifs.samba.org/src/docs/api/overview-summary.html

like image 44
Tse H.L. Avatar answered Sep 21 '22 12:09

Tse H.L.