Re: [bug] SmbFile.exists always return true
Michael B Allen <[email protected]> Mon, 1 Jun 2015 12:11:48 -0400
| Newsgroups | gmane.network.samba.java |
|---|---|
| Message-ID | <CAGMFw4iPPbbqz899dyFus1JD8cthxLcBJVWbgVnD4DuaWDFZKw@mail.gmail.com> |
On Thu, Apr 30, 2015 at 5:41 AM, YLombardi <[email protected]> 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/