Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
// template routine Java
package routines;
import jcifs.smb.*;
import java.io.*;
public class SambaTest {
private static void copySMBFile(String domain, String username, String password, String srcURL, String destFile){
try {
// To connect to a server on a remote subnet the IP address of a WINS server is required to retrieve the target address although DNS names and direct IP addresses are also valid server components within an SMB URL
// jcifs.Config.setProperty( "jcifs.netbios.wins", "192.168.1.220" );
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain, username, password);
//SmbFile(java.lang.String url, NtlmPasswordAuthentication auth)
SmbFile SF = new SmbFile(srcURL,auth);
SmbFileInputStream in = new SmbFileInputStream(SF);
File f2 = new File(destFile);
OutputStream out = new FileOutputStream(f2);
byte[] buf = new byte;
int len;
while ((len = in.read(buf)) > 0){
out.write(buf, 0, len);
}
in.close();
out.close();
} catch(FileNotFoundException ex) {
System.out.println(ex.getMessage());
} catch(IOException e) {
System.out.println(e.getMessage());
}
}
public static void main(String[] args){
SambaTest.copySMBFile("domain", "username", "password", "smb://host/dir/distantfile.txt", "C:/localfile.txt");
}
}
routines.test.SMB_connection.runSMB(context.domain, context.username, context.password, context.srcURL, context.destFile);