Discussion:
[jcifs] [bug] SmbFile.exists always return true
YLombardi
2015-04-30 09:41:24 UTC
Permalink
I'm using jcifs-1.3.17 and SmbFile and I have a strange error. I create an
SmbFile from an address that doesn't exists but when I call the exists()
method on this SmbFile, it always return true.

Here is my code :

String address = "AFalseAddress";

jcifs.Config.registerSmbURLHandler();
NtlmPasswordAuthentication auth = null;
try {
auth = new
NtlmPasswordAuthentication("ADomainThatExists","AWrongLogin","AWrongPassword");
} catch (Exception e) {
}

try {
SmbFile smbFile = new SmbFile("smb:"+address,auth);
if (smbFile.exists()) // Why is this true ???
smbFile.delete();
} catch (MalformedURLException e) {
} catch (SmbException e) {
}

I don't understand why smbfile.exists always return true even if the file
doesn't exist on the server.

Why have I this result ?



--
View this message in context: http://samba.2283325.n4.nabble.com/bug-SmbFile-exists-always-return-true-tp4685318.html
Sent from the Samba - jcifs mailing list archive at Nabble.com.
Michael B Allen
2015-06-01 16:11:48 UTC
Permalink
Post by YLombardi
I'm using jcifs-1.3.17 and SmbFile and I have a strange error. I create an
SmbFile from an address that doesn't exists but when I call the exists()
method on this SmbFile, it always return true.
String address = "AFalseAddress";
jcifs.Config.registerSmbURLHandler();
NtlmPasswordAuthentication auth = null;
try {
auth = new
NtlmPasswordAuthentication("ADomainThatExists","AWrongLogin","AWrongPassword");
} catch (Exception e) {
}
try {
SmbFile smbFile = new SmbFile("smb:"+address,auth);
if (smbFile.exists()) // Why is this true ???
smbFile.delete();
} catch (MalformedURLException e) {
} catch (SmbException e) {
}
I don't understand why smbfile.exists always return true even if the file
doesn't exist on the server.
Why have I this result ?
Hi YLombardi,

Because you have no slashes in the SMB URL so the host and everything
else is ignored (by the java.net.URL class) and so you're doing the
equivalent of SmbFile("smb:").exists() which returns true.

You want something more like:

NtlmPasswordAuthentication npa = new
NtlmPasswordAuthentication(domain, username, password);
String url = "smb://server.busicorp.local/stuff/megafile.zip";
SmbFile f = new SmbFile(url, npa);
f.exists();

Look at the jcifs.smb.SmbFile API documentation for proper SMB URL syntax.

Mike
--
Michael B Allen
Java Active Directory Integration
http://www.ioplex.com/
Loading...