【问题标题】:Copy file using last smb jcifs-ng jar使用最后一个 smb jcifs-ng jar 复制文件
【发布时间】:2019-10-30 07:19:11
【问题描述】:

尝试从 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)

编译器报告为未定义

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

【问题讨论】:

    标签: java smb jcifs


    【解决方案1】:

    工作示例:

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

    【讨论】:

      【解决方案2】:

      根据这个问题:jcifs-ng Issue #36: Chicken/egg relationship between CIFSContext and credentials

      NtlmPasswordAuthentication 类替换为 NtlmPasswordAuthenticator

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

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

      此外,this answer 可能会有所帮助。

      【讨论】:

        猜你喜欢
        • 2018-02-15
        • 2013-07-14
        • 1970-01-01
        • 2012-11-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-22
        • 2022-01-17
        • 2012-07-21
        相关资源
        最近更新 更多