[英]smb file copy results in exception
我正在嘗試將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());
確保您使用的是截至目前的最新jar,即jcifs-1.3.15.jar,而不是較低版本的jar,例如jcifs-1.1.11.jar等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.