0

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());
 }
 }
}
asked Jan 12, 2019 at 17:12

1 Answer 1

2

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());
 }
 }
}
answered Jan 12, 2019 at 17:12
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.