java jcifs.smb.SmbException: 找不到网络名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10087424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 23:34:03  来源:igfitidea点击:

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

javaweb-applicationssmb

提问by Sundhar

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

这与该特定共享文件夹的用户权限有关还是我做错了什么请指教

回答by etech

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 NtlmPasswordAuthenticationobject 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.

我遇到了这个错误信息,结果发现问题是我的网络路径不正确。您需要确保NtlmPasswordAuthentication对象配置正确,网络路径正确,并且您已正确设置 jcifs.netbios.wins 属性,如本页第一个示例所示

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)

(您需要添加 try/catch 和输入流关闭)

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:

确保所有参数都正确的一个好方法是使用 smb/cifs 客户端测试登录和定位文件。例如 linux/unix 上的 smbclient:

smbclient -Uusername -p 139 //10.10.1.1/rootfolder

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

使用 smbclient 登录时,域显示在顶部:

Domain=[DOMAINNAME]

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

..并且您可以导航到您的文件以确保路径正确。

回答by Prashant

After running into this issue for almost 1 day i realize that these exception is meaningless

在遇到这个问题将近 1 天后,我意识到这些异常毫无意义

  • I was just giving wrong path of server side location
  • 我只是给出了错误的服务器端位置路径

Below is the peace of groovy code worked for me

下面是对我来说有效的 groovy 代码的和平

        String domain = "domain"
        String user = "username"
        String pass = "password"
        String IP = "xx.yy.zz.aa"
        String sharedFolder="//my//path//to//server//";

    String path="smb://$IP"+sharedFolder+"test.txt";
    NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain, user, pass );
    SmbFile smbFile = new SmbFile(path,auth);
    SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFile);
    smbfos.write("testing....and writing to a file".getBytes());
    System.out.println("completed ...nice !");

回答by James Boutcher

I had this problem, and it turned out that I did not see what the share name was that was mapped to my Windows shared drive... So, using Mac OS, I ran:

我遇到了这个问题,结果我没有看到映射到我的 Windows 共享驱动器的共享名称是什么......所以,使用 Mac OS,我运行:

smbutil view smb://MYUSERNAME@HOSTNAME

smbutil view smb://MYUSERNAME@HOSTNAME

After I was prompted for my password, I then was displayed a list of share names (that weren't evident when I looked at this stuff using Windows). Once I found my share name, it was as simple as using that when connecting with JCIFS:

在提示我输入密码后,我会看到一个共享名称列表(当我使用 Windows 查看这些内容时,这些名称并不明显)。一旦我找到了我的共享名,就和在连接 JCIFS 时使用它一样简单:

new SmbFile("smb://HOSTNAME/SHARENAME/path/I/was/trying/to/access", auth);

new SmbFile("smb://HOSTNAME/SHARENAME/path/I/was/trying/to/access", auth);

回答by Michael

Well I'm getting this error also but only on one device, my code that works on Android 4.04 is

好吧,我也收到此错误,但仅在一台设备上,我在 Android 4.04 上运行的代码是

 String strprog = "STRING CREATED| "; //debug log string
    try {
        strprog += "NTLM| ";
        NtlmPasswordAuthentication auth =  new NtlmPasswordAuthentication("username:password");
        strprog += "SMB| ";
        SmbFile file = new SmbFile("smb://<pcname>/foldername/filename.txt",auth);

        strprog += "EXIST| ";
        String there = String.valueOf(file.exists());

        strprog += "View| ";
        TextView pp;
        pp = (TextView) findViewById(R.id.tv);
        pp.setText(there);



    } catch (Exception e) {
        // TODO Auto-generated catch block
        strprog += "ERROR! ";
        TextView ll;
        ll = (TextView) findViewById(R.id.tv);


        ll.setText(strprog + e.getStackTrace().toString() + "    " +  e.getMessage() + "   " + e.getLocalizedMessage() );
    }

The only difference I see is where you have your NtlmPasswordAuthcompared to mine. But as I stated for some reason this throws null input paramon Andriod 2.0 when I dive deeper then smb://host but I hope this helps you out.

我看到的唯一区别是你和我的NtlmPasswordAuth比较。但是正如我出于某种原因所说的那样,param当我深入研究 smb://host 时,这会在 Andriod 2.0 上抛出空输入,但我希望这对您有所帮助。