2013-10-18 36 views
1

我想複製一個jar文件到windows共享文件夾,我使用smb來做到這一點,但我得到以下錯誤。有沒有其他的方法來複制文件?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) 

我能夠寫入文件remotly。

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()); 
+0

它看起來像它可以最新的jar不建立網絡連接。您可以嘗試以不同的方式從同一臺計算機上打開共享,例如使用文件瀏覽器或「smbclient」? – chrylis

+0

我可以從共享中打開連接。此外,我也可以將文件複製到該位置。我已經更新了代碼 – Leo

+0

我對JCIFS並不熟悉,但您確定目標'smbFile'應該是一個目錄嗎? – chrylis

回答

0

確保您使用的是JCIFS-1.3.15.jar截至目前,而不是低版本,像JCIFS-1.1.11.jar等