[jcifs] [bug] SmbFile.exists always return true

Michael B Allen ioplex at gmail.com
Mon Jun 1 10:11:48 MDT 2015


On Thu, Apr 30, 2015 at 5:41 AM, YLombardi <ylombardi at geodisbm.com> wrote:
> 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 ?

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/


More information about the jCIFS mailing list