SMBJ 的连接字符串的格式是什么?有人有例子吗?我知道我可能想多了。我尝试了不同的组合,当我同时使用正斜杠和反斜杠时,它似乎在抱怨。
// trying to connect to = \\host\foldera\folderb\folderc
// tried format = smb://host/foldera/folderb/folderc/
SMBClient client = new SMBClient();
String userName = "userA";
String password = "APassword";
String domain = "ABC_DOMAIN";
String serverName = "smb://host";
String shareName = "/foldera/";
String folderName = "/folderb/folderc";
try (Connection connection = client.connect(serverName)) {
AuthenticationContext ac = new AuthenticationContext(userName, password.toCharArray(), domain);
Session session = connection.authenticate(ac);
// Connect to Share
try (DiskShare share = (DiskShare) session.connectShare(shareName)) {
for (FileIdBothDirectoryInformation f : share.list(folderName", "*.TXT")) {
System.out.println("File : " + f.getFileName());
}
}
}