在打印Windows VM中属于特定子文件夹的所有文件时,我遇到了问题。
我有一个Windows VM,其IP地址为 10.162.12.12
我要打印 C:\ MyFolder \ MySubFolder
下显示的所有文件名当前“ MySubFolder”包含4个cmd文件,即 a.cmd,b.cmd,c.cmd,d.cmd
try (Connection connection = client.connect("10.162.x.x")) {
AuthenticationContext ac = new AuthenticationContext("userName", "pwd".toCharArray(), "domainName");
Session session = connection.authenticate(ac);
// Connect to Share
try (DiskShare share = (DiskShare) session.connectShare("MyFolder")) {
for (FileIdBothDirectoryInformation f : share.list("/MySubFolder")) {
System.out.println("File : " + f.getFileName());
}
} catch (Exception e) {
e.printStackTrace();
}` `
我不确定如何传递“ C”驱动器信息和路径,即路径的传递位置。目前,我遇到以下错误:
15:48:17.991 INFO c.h.smbj.connection.Connection-已成功连接到:10.162.12.12 15:48:18.826 INFO c.h.smbj.connection.Connection-在10.162.12.12上成功验证了userName的身份,会话为140737488355349 15:48:18.826 INFO com.hierynomus.smbj.session.Session-在会话140737488355349上连接到\ 10.162.12.12 \ MyFolder 15:48:19.357 INFO com.hierynomus.smbj.session.Session-从主机10.162.12.12注销会话140737488355349 com.hierynomus.mssmb2.SMBApiException:STATUS_BAD_NETWORK_NAME(0xc00000cc):无法连接到10.162.12.12 \ MyFolder 在com.hierynomus.smbj.session.Session.connectTree(Session.java:173) 在com.hierynomus.smbj.session.Session.connectShare(Session.java:144) com.olf.agon.smbj.SMBFile3Trail.main(SMBFile3Trail.java:36)
所有我想知道如何将值传递给我的connectionShare()方法和list()方法,以便能够连接到“ \ 10.162.12.12 \ C \ MyFolder”。
答案 0 :(得分:1)
我能够解决此问题:
SmbConfig smbConfig = SmbConfig
.builder()
.withMultiProtocolNegotiate(true)
.withTransportLayerFactory(new AsyncDirectTcpTransportFactory<>())
.withSigningRequired(true).build();
final String SHARE_NAME = "C$";
final String LOCAL_PATH = "MyFolder/MySubFolder";
SMBClient client = new SMBClient(smbConfig);
try (Connection connection = client.connect("10.162.12.12")) {
AuthenticationContext ac = new AuthenticationContext("userName", "pwd".toCharArray(), "domainName");
Session session = connection.authenticate(ac);
// Connect to Share
try (DiskShare share = (DiskShare) session.connectShare(SHARE_NAME)) {
for (FileIdBothDirectoryInformation f : share.list(LOCAL_PATH)) {
System.out.println("File : " + f.getFileName());
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
client.close();
}