我在windows虚拟机中打印属于特定子文件夹的所有文件时遇到问题。
概述:
我有一个windows虚拟机,其IP地址为110.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.1215:48:18.826 INFO c.h.smbj.connection.connection-已于2012年12月10日成功验证用户名,会话为140737488835534915:48:18.826 INFO com.hierynomus.smbj.session-正在连接到\10.162.12.12\会话14073748853549上的MyFolder15:48:19.357 INFO com.hierynomus.smbj.session-从主机10.162.12.12注销会话1407374888355349com.hierynomus.mssmb.SMApiException:STATUS_BAD_NETWORK_NAME(0xc00000cc(:无法连接到10.162.12.12\MyFolder访问com.hierynomus.smbj.session.session.connectTree(会话.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";。
我能够解决这个问题:
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();
}