SMBJ:如何打印特定子文件夹中存在的所有文件
SMBJ: How to print all the files present in a particular subfolder
我在打印属于 windows VM 中特定子文件夹的所有文件时遇到问题。
概览:
我有一个 windows 虚拟机,其 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”驱动器信息和路径,即传递到哪里 path.Currently 我收到以下错误:
15:48:17.991 INFO c.h.smbj.connection.Connection - Successfully connected to: 10.162.12.12
15:48:18.826 INFO c.h.smbj.connection.Connection - Successfully authenticated userName on 10.162.12.12, session is 140737488355349
15:48:18.826 INFO com.hierynomus.smbj.session.Session - Connecting to .162.12.12\MyFolder on session 140737488355349
15:48:19.357 INFO com.hierynomus.smbj.session.Session - Logging off session 140737488355349 from host 10.162.12.12
com.hierynomus.mssmb2.SMBApiException: STATUS_BAD_NETWORK_NAME (0xc00000cc): Could not connect to 10.162.12.12\MyFolder
at com.hierynomus.smbj.session.Session.connectTree(Session.java:173)
at com.hierynomus.smbj.session.Session.connectShare(Session.java:144)
at com.olf.agon.smbj.SMBFile3Trail.main(SMBFile3Trail.java:36)
我只想知道如何将值传递给我的 connectionShare() 方法和 list() 方法,以便我能够连接到“\10.162.12.12\C\MyFolder”。
我能够解决这个问题:
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();
}
我在打印属于 windows VM 中特定子文件夹的所有文件时遇到问题。
概览:
我有一个 windows 虚拟机,其 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”驱动器信息和路径,即传递到哪里 path.Currently 我收到以下错误:
15:48:17.991 INFO c.h.smbj.connection.Connection - Successfully connected to: 10.162.12.12 15:48:18.826 INFO c.h.smbj.connection.Connection - Successfully authenticated userName on 10.162.12.12, session is 140737488355349 15:48:18.826 INFO com.hierynomus.smbj.session.Session - Connecting to .162.12.12\MyFolder on session 140737488355349 15:48:19.357 INFO com.hierynomus.smbj.session.Session - Logging off session 140737488355349 from host 10.162.12.12 com.hierynomus.mssmb2.SMBApiException: STATUS_BAD_NETWORK_NAME (0xc00000cc): Could not connect to 10.162.12.12\MyFolder at com.hierynomus.smbj.session.Session.connectTree(Session.java:173) at com.hierynomus.smbj.session.Session.connectShare(Session.java:144) at com.olf.agon.smbj.SMBFile3Trail.main(SMBFile3Trail.java:36)
我只想知道如何将值传递给我的 connectionShare() 方法和 list() 方法,以便我能够连接到“\10.162.12.12\C\MyFolder”。
我能够解决这个问题:
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();
}