Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connecting to shared folder in windows with java

Tags:

java

jcifs

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

 File file = new File("\\\\theRemoteIP\\webapps");        File[] files = file.listFiles();       System.out.println("access done");        for (int i = 0; i < files.length; i++)       {           String name = files[i].getName();           System.out.println(name);       }   

Thanks

like image 499
SShehab Avatar asked Jan 31 '10 13:01

SShehab


1 Answers

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()); } 
like image 55
Valentin Rocher Avatar answered Oct 19 '22 18:10

Valentin Rocher