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());
}
}
}发布于 2019-01-12 17:12:35
是的,我想得太多了。字面上就是这么简单。见例子。
// trying to connect to = "\\MyHost\MyShareName\FolderA\FolderB"
SMBClient client = new SMBClient();
String userName = "userA";
String password = "APassword";
String domain = "ABC_DOMAIN";
String serverName = "MyHost";
String shareName = "MyShareName";
String folderName = "FolderA\FolderB";
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());
}
}
}https://stackoverflow.com/questions/54161972
复制相似问题