Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SMBJ:如何打印特定子文件夹中的所有文件_Java_Smbj - Fatal编程技术网

Java SMBJ:如何打印特定子文件夹中的所有文件

Java SMBJ:如何打印特定子文件夹中的所有文件,java,smbj,Java,Smbj,我在打印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")) { AuthenticationConte

我在打印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”驱动器信息和路径,即传递路径的位置。目前我遇到以下错误:

15:48:17.991信息c.h.smbj.connection.connection-已成功连接到:10.162.12.12 15:48:18.826 INFO c.h.smbj.connection.connection-成功验证了10.162.12.12上的用户名,会话为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注销会话140737488355349 com.hierynoms.mssmb2.SMBApiException:状态\坏\网络\名称(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”。

我能够解决此问题:

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();
    }
SmbConfig SmbConfig=SmbConfig
.builder()
.使用多协议协商(真)
.withTransportLayerFactory(新的AsyncDirectTcpTransportFactory())
.withSigningRequired(true).build();
最终字符串共享_NAME=“C$”;
最终字符串LOCAL_PATH=“MyFolder/MySubFolder”;
SMBClient=新的SMBClient(smbConfig);
try(Connection=client.connect(“10.162.12.12”)){
AuthenticationContext ac=新的AuthenticationContext(“用户名”,“pwd”.toCharArray(),“域名”);
会话=连接。身份验证(ac);
//连接到共享
try(DiskShare=(DiskShare)session.connectShare(share\u NAME)){
for(FileIdBothDirectoryInformation f:share.list(本地路径)){
System.out.println(“文件:+f.getFileName());
}
}捕获(例外e){
e、 printStackTrace();
}
}捕获(例外e){
e、 printStackTrace();
}最后{
client.close();
}