【问题标题】:Accessing Windows Shared folder using JCIFS使用 JCIFS 访问 Windows 共享文件夹
【发布时间】:2018-09-10 16:17:32
【问题描述】:

我在使用 JCIFS 从 Java 应用程序连接到 samba 驱动器时遇到问题。问题似乎是 JCiFS 想要连接的 url。我无法输入服务器名称/文件夹/文件夹,因为我无权登录服务器以获取文件夹。我所拥有的是通过 Samba 访问服务器上的文件夹。我可以通过 windows \celery\rim\dev 映射它,但不能在 url 中使用它来传递给 JCIFS。

下面的 url 没有进入 dev 目录。如果我只执行 smb://celery/rim/ 就可以进入,但这不是正确的目录,我需要向下移动到 dev 目录。

String url = "smb://celery/rim/dev/";
    NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("domain", "user", "password");
    try {
        SmbFile dir = new SmbFile(url, auth);
 String[] content = dir.list();
        for(String file : content){
            System.out.println(file);
        }

【问题讨论】:

  • 您的 Windows 版本是多少?也许 SMB1 在此 Windows 中已禁用。 JCIFS 仅适用于 SMB1

标签: java jcifs


【解决方案1】:

@Eliad Cohen - 我确信这就是问题所在。我通过迁移到 JCIFS-ng 解决了这个问题。我只是希望他们有更好的文档。

CIFSContext baseCxt = new BaseContext(new PropertyConfiguration(System.getProperties()));
        NtlmPasswordAuthentication creds = new NtlmPasswordAuthentication(baseCxt, "am", nasProperties.getUsername(),nasProperties.getPassword());
        CIFSContext ct = baseCxt.withCredentials(creds);
        SmbFile dir = new SmbFile(url, ct);

        SmbFileOutputStream sfos = new SmbFileOutputStream(dir);
        sfos.write(csv.getBytes());

        sfos.close();

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-20
  • 1970-01-01
  • 2012-12-06
  • 1970-01-01
  • 2020-01-14
  • 2012-10-22
  • 2011-11-02
相关资源
最近更新 更多