com.hierynomus.smbj.SMBClient Java Examples

The following examples show how to use com.hierynomus.smbj.SMBClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Samba2FileSystem.java    From iaf with Apache License 2.0 9 votes vote down vote up
@Override
public void open() throws FileSystemException {
	try {
		AuthenticationContext auth = authenticate();
		client = new SMBClient();
		connection = client.connect(domain);
		if(connection.isConnected()) {
			log.debug("successfully created connection to ["+connection.getRemoteHostname()+"]");
		}
		session = connection.authenticate(auth);
		if(session == null) {
			throw new FileSystemException("Cannot create session for user ["+username+"] on domain ["+domain+"]");
		}
		diskShare = (DiskShare) session.connectShare(shareName);
		if(diskShare == null) {
			throw new FileSystemException("Cannot connect to the share ["+ shareName +"]");
		}
	} catch (IOException e) {
		throw new FileSystemException("Cannot connect to samba server", e);
	}
}
 
Example #2
Source File: SMBJController.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public boolean linkStart(SmbLinkInfo smbLinkInfo, SmbLinkException exception) {
    String rootFolder = smbLinkInfo.getRootFolder();
    if (SmbUtils.isTextEmpty(rootFolder)) {
        exception.addException(SmbType.SMBJ, "Root Folder Must Not Empty");
        return false;
    }

    SmbConfig smbConfig = SmbConfig.builder()
            .withTimeout(180, TimeUnit.SECONDS)
            .withSoTimeout(180, TimeUnit.SECONDS)
            .build();

    try {
        smbClient = new SMBClient(smbConfig);
        connection = smbClient.connect(smbLinkInfo.getIP());
        AuthenticationContext ac = new AuthenticationContext(
                smbLinkInfo.getAccount(), smbLinkInfo.getPassword().toCharArray(), smbLinkInfo.getDomain());
        session = connection.authenticate(ac);

        ROOT_FLAG += smbLinkInfo.getRootFolder();
        mPath = ROOT_FLAG;

        diskShare = (DiskShare) session.connectShare(smbLinkInfo.getRootFolder());
        rootFileList = getFileInfoList(diskShare.list(""), diskShare);

        return true;
    } catch (Exception e) {
        e.printStackTrace();
        exception.addException(SmbType.SMBJ, e.getMessage());
    }
    return false;
}
 
Example #3
Source File: SMBJ_RPCController.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public boolean linkStart(SmbLinkInfo smbLinkInfo, SmbLinkException exception) {

    //set smb config
    SmbConfig smbConfig = SmbConfig.builder()
            .withTimeout(180, TimeUnit.SECONDS)
            .withSoTimeout(180, TimeUnit.SECONDS)
            .build();

    try {
        smbClient = new SMBClient(smbConfig);
        smbConnection = smbClient.connect(smbLinkInfo.getIP());
        AuthenticationContext authContext = new AuthenticationContext(
                smbLinkInfo.getAccount(), smbLinkInfo.getPassword().toCharArray(), smbLinkInfo.getDomain());
        session = smbConnection.authenticate(authContext);

        RPCTransport transport = SMBTransportFactories.SRVSVC.getTransport(session);
        ServerService serverService = new ServerService(transport);
        List<NetShareInfo0> shareInfoList = serverService.getShares0();

        mPath = ROOT_FLAG;

        //get root directory file list
        rootFileList = getFileInfoList(shareInfoList);

        return true;
    } catch (Exception e) {
        e.printStackTrace();
        exception.addException(SmbType.SMBJ_RPC, e.getMessage());
    }
    return false;
}
 
Example #4
Source File: PooledSMB2Connection.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Connection openConnection() throws IOException {
	String host = authority.getHost();
	int port = authority.getPort();
	
	SmbConfig config = SmbConfig.createDefaultConfig(); // TODO: SmbConfig - SMB2 dialects, timeouts, proxy
	SMBClient client = new SMBClient(config);
	
	if (port < 0) {
		return client.connect(host);
	} else {
		return client.connect(host, port);
	}
}