SMBJ 连接字符串
SMBJ Connection String
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());
}
}
}
是的,我想多了。从字面上看就是这么简单。参见示例。
// 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());
}
}
}
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());
}
}
}
是的,我想多了。从字面上看就是这么简单。参见示例。
// 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());
}
}
}