4

Trying to move from jcifs to jcifs-ng (the latest jar jcifs-ng-2.1.2.jar) to copy files to/from remote. My code using old jcifs:

    System.setProperty("jcifs.smb.client.responseTimeout", "10000");
    System.setProperty("jcifs.smb.client.soTimeout", "2000");
    if (winsIPList.trim().equals("")) {
        System.setProperty("jcifs.smb.client.dfs.disabled", "true");             
    } else {
       System.setProperty("jcifs.smb.client.dfs.disabled", "false");
       System.setProperty("jcifs.netbios.wins", winsIPList.trim());
       System.setProperty("resolveOrder", "DNS");
    }
    NtlmPasswordAuthentication auth = new 
    NtlmPasswordAuthentication(filesrvDomainIP, filesrvDomainUser,
                    filesrvDomainPassword);
    smbRemoteFile = new SmbFile("smb:" + remoteFile.replace("\\", "/"), auth);
    <here the code to copy file>

Found few examples in stackoverflow, but looks like they are old.

Part of them include usage of NtlmPasswordAuthentication(context, DomainIP, DomainUser,DomainPassword) which is deprecated in the last jcifs-ng package.

Others use

SmbFile smbRemoteFile = new SmbFile(remoteFile, someContext)

which is reported as undefined by compiler

Could somebody provide an example that works?

howie
  • 2,587
  • 3
  • 27
  • 43
Lubov Shilin
  • 133
  • 2
  • 10

2 Answers2

7

Working example:

BaseContext baseCxt = null;
Properties jcifsProperties  = new Properties();
jcifsProperties.setProperty("jcifs.smb.client.enableSMB2", "true");
jcifsProperties.setProperty("jcifs.smb.client.dfs.disabled","true");
Configuration config = new PropertyConfiguration(jcifsProperties);
baseCxt = new BaseContext(config);
auth = baseCxt.withCredentials(new NtlmPasswordAuthenticator(DomainIP, DomainUser,
                    DomainPassword));
SmbFile smbRemoteFile = new SmbFile("smb:" + remoteFile.replace("\\", "/"), auth);
Lubov Shilin
  • 133
  • 2
  • 10
1

According to this issue: jcifs-ng Issue #36: Chicken/egg relationship between CIFSContext and credentials

Class NtlmPasswordAuthentication is replaced by NtlmPasswordAuthenticator.

So you might replace your NtlmPasswordAuthentication usage with:

NtlmPasswordAuthenticator auth = new NtlmPasswordAuthenticator(domain, username, password)

Besides, this answer might be helpful.