The Java CIFS Client Library
JCIFS is an Open Source client library that implements the CIFS/SMB networking protocol in 100% Java. CIFS is the standard file sharing protocol on the Microsoft Windows platform (e.g. Map Network Drive ...). This client is used extensively in production on large Intranets.1)Download JCIFS using below URL
http://jcifs.samba.org/src/jcifs-1.3.16.zip
2)One sample program for accessing a file of other systems which is in network and writing something on that.
Logon.java
------------------------------------------------------
import java.io.FileOutputStream;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileInputStream;
import jcifs.smb.SmbFileOutputStream;
public class Logon {
public static void main( String argv[] ) throws Exception {
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("ISSHYD.COM", "isshyd\\kirankumar.g", "indiangk1791$");
String path = "smb://192.168.1.209/D$/file1.txt";
SmbFile sFile = new SmbFile(path, auth);
SmbFileOutputStream sfos = new SmbFileOutputStream(sFile,true);
sfos.write("\n append-kiran6".getBytes());
System.out.println("Done");
// sFile.delete();
}
}
Note :
Add jcifs.jar in build path before running this program
In this program,
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", "username", "password");
ISSHYD.COM----------->is domaine name of system to access(MyComputer-->Right click-->then see once your domain name of system)(giving domain name is not necessary you can give empty "" )
isshyd\\kirankumar.g-------->is username of system to access
indiangk1791$------------->is password of system to access.
192.168.1.209-------------->IP Address of system to access.
in this program i am accessing file1.txt file in D drive of System and wrote some thing on that file.
Note2:once see jcifs home/examples folder sample programs.
3)Another Sample program to access all the folders and files of a specific directory.
Here i am accessing all the files and folders of D drive.
Sample1.java
---------------------------------------------------------------
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
public class Sample1 {
public static void main( String argv[] ) throws Exception {
//String user = "ISSHYD\\kirankumar.g:indiangk1791$";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("domaine", "username", "password");
String path = "smb://192.168.1.214/D$/";
SmbFile sFile = new SmbFile(path, auth);
SmbFile[] files = sFile.listFiles();
System.out.println("files");
for (SmbFile x : files) {
System.out.println("file: " + x + ". path: " + x.getPath() + ". isDirectory? " + x.isDirectory());
if (x.isDirectory()) {
for (SmbFile dir : x.listFiles()) {
System.out.println("dir file: " + dir + ". path: " + dir.getPath() + ". isDirectory? " + dir.isDirectory());
}
}
}
}
}