protocole SMB :: Samba

Seventeen Stars

protocole SMB :: Samba

hi,
Sometime i have to get data from OS windows ; i've got a a samba "partage" with it to retrieve them ... manually.
So it will be helpfully to access those repositories by protocole smb:// .............
thanks for your attention
Employee

Re: protocole SMB :: Samba

Hello,
Here is a java routine that will help you.
In order to use it, you will need to download the jcifs library from http://jcifs.samba.org/src/ and add it to the routine libraries (Right Click on the routine, Edit Routine Libraries)
If you find it interesting, you can ask for a feature request on tFileFetch component to support smb protocol.
Regards,
// 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");
}
}
Seventeen Stars

Re: protocole SMB :: Samba

thanks a lot mhirt
I didn't know anything about this library , and it 'll resolve some of my "problems" ...
In fact we're plan to migrate all applications on a OS linux but we can do all things we'd like to. (lol for my frenglish)
never mind , il'll going to try you code right now and effectively a tFileFech Smtp 'll be hepfully for some occasions
... seems to be
Employee

Re: protocole SMB :: Samba

Time to use the http://talendforge.org/bugs ;-)
Seventeen Stars

Re: protocole SMB :: Samba

your code works perfectly ...
I can now retrieve easily any files I want with "SMB" protocole with a tJavaFlex component (so simple)
routines.test.SMB_connection.runSMB(context.domain, context.username, context.password, context.srcURL, context.destFile);

PS : I've tried to add "a feature" in the bugtracker" but didn't find the way to (sic) !
Employee

Re: protocole SMB :: Samba

I have create feature request 5503
Regards,
Seventeen Stars

Re: protocole SMB :: Samba

thanks a lot
Regards
laurent