سؤال

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

Try using new SmbFile("smb://host-name-for-my-pc/", authentication);. With a slash at the end.

I was experiencing the same problem with the library. I could see that all answers that resolved the problem didn't have the domain attribute, I tried without that attribute and I saw that the problem was resolved, I think that the library is used in LANs by default, but if you explicitly put the domain the execution is slow.

About the password, I think that is normal that the login to the shared folder is slower.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top