Reputation: 153
What is the format of the connection String(s) for SMBJ? Does anybody have an example? I know I'm probably overthinking this. I've tried different combinations, and it seems to complain when I use both forward and backward slashes.
// 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());
}
}
}
Upvotes: 0
Views: 2721
Reputation: 153
Yup, I was overthinking it. It literally is that simple. See example.
// 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());
}
}
}
Upvotes: 2