com.hierynomus.smbj.SmbConfig Java Examples

The following examples show how to use com.hierynomus.smbj.SmbConfig. 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: 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 #2
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 #3
Source File: PooledSMB2Connection.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void connect() throws IOException {
	this.connection = openConnection();

       NegotiatedProtocol negotiatedProtocol = connection.getNegotiatedProtocol();
       SmbConfig config = connection.getConfig();
	writeBufferSize = Math.min(config.getWriteBufferSize(), negotiatedProtocol.getMaxWriteSize());

	try {
		this.session = startSession();
	} catch (NoClassDefFoundError error) {
		throw new MissingBouncyCastleException("SMB 2.x requires Bouncy Castle cryptographic library. Please visit http://doc.cloverdx.com/documentation/UserGuide/topic/com.cloveretl.gui.docs/docs/optional-installation-steps.html#smb-support for installation instructions.", error);
	}
	this.share = connectShare();
}
 
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);
	}
}