jcifs.smb.SmbException: The network name cannot be found

Sundhar picture Sundhar · Apr 10, 2012 · Viewed 22.3k times · Source

The following is my piece of code

SmbFile catalExp = new SmbFile("smb://<Shared machine name>/Project share/Home/4.  Folders/planning - Design & Exec/sample.txt",
                    new NtlmPasswordAuthentication(LoadProp.getShrdDomain(),"user","paswd"));

In this i am getting the error

jcifs.smb.SmbException: The network name cannot be found
    at jcifs.smb.SmbTransport.send(SmbTransport.java:753)
    at jcifs.smb.SmbSession.sessionSetup(SmbSession.java:140)
    at jcifs.smb.SmbSession.send(SmbSession.java:103)
    at jcifs.smb.SmbTree.treeConnect(SmbTree.java:132)
    at jcifs.smb.SmbFile.connect(SmbFile.java:674)
    at jcifs.smb.SmbFile.connect0(SmbFile.java:644)
    at jcifs.smb.SmbFile.open0(SmbFile.java:700)
    at jcifs.smb.SmbFile.createNewFile(SmbFile.java:2027)

Is this anything to do with the user rights to that particular shared folder or am I doing anything wrong Please advice

Answer

etech picture etech · May 26, 2013

I ran into this error message, and it turned out the problem was that my network path was incorrect. You'll want to ensure that the NtlmPasswordAuthentication object is configured correctly, that your network path is correct, and that you've set the jcifs.netbios.wins property correctly, as indicated in the first example on this page.

For example, to load a remote properties file:

final NtlmPasswordAuthentication AUTH = new NtlmPasswordAuthentication("domainname", "username", "password");

Config.setProperty("jcifs.netbios.wins", "10.10.1.1");

Properties props = new Properties();
InputStream in = new SmbFileInputStream(new SmbFile("smb://10.10.1.1:445/rootfolder/path/filename.properties", AUTH));
props.load(in);

(You'll need to add try/catch and input stream closing)

A good way to ensure that all of your parameters are correct is to test logging into and locating the file using a smb/cifs client. For example smbclient on linux/unix:

smbclient -Uusername -p 139 //10.10.1.1/rootfolder

The domain is displayed at the top when you login with smbclient:

Domain=[DOMAINNAME]

..and you can navigate to your file to make sure you've got the path correct.