connecting to shared folder in windows with java

If you are accessing open shared folders (i.e. username or password are not known or required),then you can follow the code below :

String path="smb://172.16.0.11/";

SmbFile smbFile = new SmbFile(path);
String a[]=smbFile.list();
for(int i=0;i<a.length;i++)
{
    System.out.println(a[i]);
}

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());
}

Tags:

Java

Jcifs