gpt4 book ai didi

java - smb 文件复制导致异常

转载 作者:行者123 更新时间:2023-12-01 04:15:53 26 4
gpt4 key购买 nike

我正在尝试将 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,而不是 jcifs-1.1.11.jar 等较低版本。

关于java - smb 文件复制导致异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19460495/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com