Java开源samba client项目之jcifs/jcifs-ng库

本文介绍了Java开源SMB客户端jcifs及其后续改进版jcifs-ng,强调jcifs仅支持SMB1且已被微软弃用。jcifs-ng支持SMB2并包含部分SMB3实验性支持,提供了更现代的API。文章详细梳理了jcifs-ng的特性和常用方法,包括SmbFile、CIFSContext接口,以及如何进行文件操作、认证和连接。还讨论了SMB2协议、NTLM认证,并提供了相关资源链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Java开源samba client

jcifs

官网: https://www.jcifs.org/

官方翻译描述:

感谢Samba组织主办JCIFS项目18年!

如果您正在寻找最新和最大的开源Java SMB库,这不是它。JCIFS仅在维护模式下运行了几年,尽管它所支持的功能运行良好(smb1、ntlmv2、milc、msrpc和各种实用程序类),但JCIFS不支持较新的smb2/3变种的smb2/3,这种变种的smb2/3正逐渐成为必需的(Windows 10需要smb2/3)。**JCIFS只支持SMB1,但微软在其产品中已弃用了SMB1。**因此,如果在您的网络上禁用了smb1,jcifs的文件相关操作将无法工作。

幸运的是,有多种新的开源SMB Java项目来尝试包括以下内容:

  • jcifs-ng
    A cleaned-up and improved version of the jCIFS library
    一个经过清理和改进的JCIFS库版本
  • smbj
    smbj - SMB2/SMB3 client library for Java

关于JCIFS,maven描述:
JCIFS is an Open Source client library that implements the CIFS/SMB networking protocol in 100% Java
最新版本发布时间比较老,2012年。

关于 JCIFS NG maven中央仓库描述:
A pure-java CIFS/SMB client library
最新版本发布时间2019

关于 SMBJ maven中央仓库描述:
SMB2 protocol library for communication with Windows servers
最新版本发布时间2018

JCIFS NG

git官网:https://github.com/AgNO3/jcifs-ng

      <!--java samba client api-->
      <dependency>
          <groupId>eu.agno3.jcifs</groupId>
          <artifactId>jcifs-ng</artifactId>
          <version>2.1.3</version>
      </dependency>

jcifs-ng 2.1

This release enables SMB2 support by default and contains some experimental SMB3.0 support.

Protocol levels negotitated can now be controlled with jcifs.smb.client.minVersion and jcifs.smb.client.maxVersion (this deprecates the jcifs.smb.client.enableSMB2 / jcifs.smb.client.disableSMB1 properties). Default min/max versions are SMB1 to SMB210.

This release deprecates server browsing (i.e. server/workgroup enumeration) and contains some breaking API changes regarding authentication.

这个版本默认启用了smb2支持,并包含一些实验性的smb3.0支持。

协议级别协商现在可以使用jcifs.smb.client.minversion和jcifs.smb.client.maxversion进行控制(取消jcifs.smb.client.enablesmb2/jcifs.smb.client.disablesmb1属性)。默认的最小/最大版本是smb1到smb210。

此版本不支持服务器浏览(即服务器/工作组枚举),并包含一些有关身份验证的破坏性API更改。

常用类和方法整理

SmbFile: 此类标识在samba网络上的一个资源。主要资源是文件或目录,不过SmbFile也可以是服务或工作组。SmbFile实例是不可变对象。因此,一旦创建,代表这个对象的绝对路径pathname就不会改变。

/**
 * This class represents a resource on an SMB network. Mainly these
 * resources are files and directories however an <code>SmbFile</code>
 * may also refer to servers and workgroups. If the resource is a file or
 * directory the methods of <code>SmbFile</code> follow the behavior of
 * the well known {@link java.io.File} class. One fundamental difference
 * is the usage of a URL scheme [1] to specify the target file or
 * directory. SmbFile URLs have the following syntax:
 *
 。。。
  * Instances of the <code>SmbFile</code> class are immutable; that is,
 * once created, the abstract pathname represented by an SmbFile object
 * will never change.

CIFSContext接口

api测试

api使用基本套路:如下简单的demo测试,需要一个 CIFSContext 实例以及一个 sambaURL ,利用new SmbFile传入这两个参数。利用SmbFile实例的方法来操作。核心就是 SmbFile类提供的各种方法,来完成各种samba操作。

public class BaseCIFSTest {
   


    public static void main(String[] args) {
   

        String ip = "11.11.111.111";
        String dir = "LogDir";
        String shareUrl = "smb://" + ip + "/" + dir + "/";


        Properties props = new Properties();
        //props.putAll(this.properties);
        CIFSContext ctx  = null;
        try {
   
            ctx = new BaseContext(new PropertyConfiguration(props));
            SmbResource f = new SmbFile(shareUrl, ctx.withAnonymousCredentials());
            System<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西京刀客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值