1.smb1,smb2,smb3协议

目前了解到的是 微软的共享目录一共有这三个协议

smb1 可以使用 JCIFS的网址: http://jcifs.samba.org/   这里的api 使用 百度很多不在叙述

读取windows电脑上共享目录的操作

最大的缺点 only for smb1

smb2,smb3 可以使用 smbj  github 上地址: https://github.com/hierynomus/smbj

具体的api 使用 比jcifs 复杂点  以下 是我读取我局域网内 一个 excel 文件的代码

public static InputStream smbGet1(String filename) throws IOException {
    SMBClient client = new SMBClient();
    Connection connection = client.connect("10.69.22.181");
    AuthenticationContext ac = new AuthenticationContext("[email protected]", "XXXXX".toCharArray(), "");
    Session session = connection.authenticate(ac);
    File f = null;
    // Connect to Share
    try  {
      DiskShare share = (DiskShare) session.connectShare("Shared");
        f = share.openFile(filename,
            new HashSet(Arrays.asList(AccessMask.GENERIC_ALL)),
            new HashSet(Arrays.asList(FileAttributes.FILE_ATTRIBUTE_NORMAL)),
            SMB2ShareAccess.ALL,
            SMB2CreateDisposition.FILE_OPEN,
            new HashSet(Arrays.asList(SMB2CreateOptions.FILE_DIRECTORY_FILE))
        );
    }catch (Exception e){
      e.printStackTrace();
    }
    return f.getInputStream();
  }

以上代码返回的 inportStream 以流形式 读出来

相关文章:

  • 2021-04-06
  • 2022-12-23
  • 2021-05-11
  • 2021-07-04
  • 2021-05-06
  • 2021-10-26
  • 2022-12-23
  • 2021-11-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2021-12-07
  • 2021-07-18
  • 2022-12-23
  • 2021-07-28
相关资源
相似解决方案