【问题标题】:SMBJ: How to print all the files present in a particular subfolderSMBJ:如何打印特定子文件夹中的所有文件
【发布时间】:2021-01-03 20:25:51
【问题描述】:

我在打印属于 Windows VM 中特定子文件夹的所有文件时遇到问题。

概述:

我有一个IP地址为10.162.12.12

的windows VM

我想打印 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 上成功验证了用户名,会话为 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”。

【问题讨论】:

    标签: java smbj


    【解决方案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();
        }
    

    【讨论】:

    • Connection connection = client.connect("10.162.12.12") - 连接本地目录是否需要认证?如果是,可能是什么凭据,是用户凭据吗?
    猜你喜欢
    • 2020-05-16
    • 1970-01-01
    • 2017-04-22
    • 2012-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-01
    • 2016-01-16
    相关资源
    最近更新 更多