为了账号安全,请及时绑定邮箱和手机立即绑定

SMBJ 连接字符串

SMBJ 连接字符串

饮歌长啸 2022-04-28 17:08:58
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());        }    }}
查看完整描述

1 回答

?
拉丁的传说

TA贡献1789条经验 获得超8个赞

是的,我想多了。从字面上看就是这么简单。见例子。


// 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());

        }

    }

}


查看完整回答
反对 回复 2022-04-28
  • 1 回答
  • 0 关注
  • 174 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信