1

我正在尝试将 jar 文件复制到 Windows 共享文件夹,并且我正在使用 smb 来执行此操作,但出现以下错误。有没有其他方法可以复制文件?

    String user = "abc";
    String pass ="xyz";
    try{
        String sharedFolder="tmp/share/sample.jar";
        String path="smb://1.2.3.4/"+sharedFolder;
        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("",user, pass);
        SmbFile smbFile = new SmbFile(path,auth);
        SmbFile localFile = new SmbFile("C:/abc/exz/sample.jar");
        localFile.copyTo(smbFile);

    }catch(Exception e){
        e.printStackTrace();
    }

例外 :

jcifs.smb.SmbException: Failed to negotiate
jcifs.smb.SmbException: Timeout trying to open socket
    at jcifs.smb.SmbTransport.start(SmbTransport.java:315)
    at jcifs.smb.SmbTransport.negotiate0(SmbTransport.java:865)
    at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:941)
    at jcifs.smb.SmbTree.treeConnect(SmbTree.java:119)
    at jcifs.smb.SmbFile.connect(SmbFile.java:827)
    at jcifs.smb.SmbFile.connect0(SmbFile.java:797)
    at jcifs.smb.SmbFile.copyTo(SmbFile.java:2022)
    at copyToWindows.copyFile(copyToWindows.java:26)
    at copyToWindows.main(copyToWindows.java:14)

    at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:947)
    at jcifs.smb.SmbTree.treeConnect(SmbTree.java:119)
    at jcifs.smb.SmbFile.connect(SmbFile.java:827)
    at jcifs.smb.SmbFile.connect0(SmbFile.java:797)
    at jcifs.smb.SmbFile.copyTo(SmbFile.java:2022)
    at copyToWindows.copyFile(copyToWindows.java:26)
    at copyToWindows.main(copyToWindows.java:14)

我能够远程写入文件。

String sharedFolder="tmp/share/text.txt";
        String path="smb://1.2.3.4/"+sharedFolder;
        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("",user, pass);
        SmbFile smbFile = new SmbFile(path,auth);
        SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFile);
    smbfos.write("TEsting ".getBytes());
4

1 回答 1

0

确保您使用的是最新的 jar,即 jcifs-1.3.15.jar,而不是 jcifs-1.1.11.jar 等较低版本。

于 2014-09-17T10:22:49.490 回答