簡體   English   中英

使用最后一個 smb jcifs-ng jar 復制文件

[英]Copy file using last 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 Issue #36:CIFSContext 和憑證之間的雞/蛋關系

NtlmPasswordAuthentication被替換NtlmPasswordAuthenticator

因此,您可以將NtlmPasswordAuthentication用法替換為:

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

此外,這個答案可能會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM