如何解决jcifs.smb.SmbException:连接失败:0.0.0.0<00>/192.168.43.103 jcifs.util.transport.TransportException java.net.SocketException
当我尝试读取 smb
文件时出现此错误。
附注
C:\Windows\system32> Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol
FeatureName : SMB1Protocol
DisplayName : SMB 1.0/CIFS File Sharing Support
Description : Support for the SMB 1.0/CIFS file sharing protocol,and the
Computer Browser protocol.
RestartRequired : Possible
State : Enabled
CustomProperties :
ServerComponent\Description : Support for the SMB 1.0/CIFS
file sharing protocol,and the Computer Browser protocol. ServerComponent\DisplayName : SMB 1.0/CIFS File Sharing Support
ServerComponent\Id : 487
ServerComponent\Type : Feature
ServerComponent\UniqueName : FS-SMB1
ServerComponent\Deploys\Update\Name : SMB1Protocol
它说我的 smb1
已启用,但我仍然收到此错误。
package shared_folder;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import java.net.MalformedURLException;
public class Main {
public static void main(String[] args) {
String url = "smb://192.168.43.103/shared/";
String userName = "shyam";
String password = "shyam";
String domain = null;
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null,userName,password);
try {
doRecursiveLookup(new SmbFile(url,auth));
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
/*
* Recursively scans through the folder for files and prints the name of folder and file
*/
public static void doRecursiveLookup(SmbFile smb) {
try {
if (smb.isDirectory()) {
System.out.println(smb.getName());
for (SmbFile f : smb.listFiles()) {
if (f.isDirectory()) {
doRecursiveLookup(f);
} else {
System.out.println("\t:" + f.getName());
}
}
} else {
System.out.println("\t:" + smb.getName());
}
} catch (SmbException e) {
e.printStackTrace();
}
}
}
解决方法
如果您使用的是 Windows 10,则需要使用并启用 SMB2! (并可选择禁用 SMB1)
可能的解决方案: SmbException failed to connect hostname/IP_address throwing with proper credentials in Java
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。