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?
Using new SmbFile("username:password@server/")
works, so I'm just using that.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With