使用最后一个 smb jcifs-ng jar 复制文件



尝试从jcifs移动到jcifs-ng(最新的jar jcifs-ng-2.1.2.jar(以将文件复制到/从远程复制文件。我使用旧 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>

在 stackoverflow 中发现的例子很少,但看起来它们很旧。

其中一部分包括NtlmPasswordAuthentication(context,DomainIP,DomainUser,DomainPassword(的使用,在最后一个jcifs-ng包中已弃用。

其他使用

SmbFile smbRemoteFile = new SmbFile(remoteFile, someContext)

被编译器报告为未定义

有人可以提供一个有效的例子吗?

工作示例:

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);

根据此问题:jcifs-ng 问题 #36:CIFSContext 和凭据之间的鸡/蛋关系

NtlmPasswordAuthentication 替换为 NtlmPasswordAuthenticator

因此,您可以将NtlmPasswordAuthentication用法替换为:

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

此外,这个答案可能会有所帮助。

最新更新