Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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
Labels (2)
6 Replies
Anonymous
Not applicable
Author

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");
}
}
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

Time to use the http://talendforge.org/bugs 😉
Anonymous
Not applicable
Author

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) !
Anonymous
Not applicable
Author

I have create feature request 5503
Regards,
Anonymous
Not applicable
Author

thanks a lot
Regards
laurent