connecting to shared folder in windows with java

后端 未结 2 1224
夕颜
夕颜 2020-11-28 07:19

I need to connect to a shared folder on a remote windows machine through java , where i put my domain authentication (username and password ) in the code , here is my code

2条回答
  •  离开以前
    2020-11-28 07:49

    You should use SmbFile and NtlmPasswordAuthentication from JCIFS. Here is a simple piece of code to show you how to do :

    String url = "smb://yourhost/yourpath/";
    NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "user", "password");
    SmbFile dir = new SmbFile(url, auth);
    for (SmbFile f : dir.listFiles())
    {
        System.out.println(f.getName());
    }
    

提交回复
热议问题