jcifs使用踩坑

工作需求要远程控制公共盘,百度了一圈发现能用jcifs实现

添加依赖

<dependency>
<groupId>jcifs</groupId>
<artifactId>jcifs</artifactId>
<version>1.3.17</version>
</dependency>
这边有个问题,网上的教程一般用的版本都是1.3.3,我用1.3.3的话会报错,改成1.3.17一切正常,原因未知
jcifs.util.transport.TransportException Connection reset

springboot 版本是2.5.2
public class demo2 {
private static String USER_DOMAIN = ""; //域账号,没有可以不填
private static String USER_ACCOUNT = "test"; //账号
private static String USER_PWS = "test"; //密码

public static void main(String[] args) throws Exception {

String shareDir = "smb://xxx.xxx.xx.xx/sharemovie";
copyFiles(shareDir);
}

public static void copyFiles(String shareDirectory) throws IOException {
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(USER_DOMAIN,USER_ACCOUNT, USER_PWS);
SmbFile remoteFile = new SmbFile(shareDirectory+"/aa.txt", auth);
SmbFile targetFile = new SmbFile(shareDirectory+"/a/aa.txt", auth);
if (remoteFile.exists()) {
System.out.println("yes");
remoteFile.copyTo(targetFile);
}else{
System.out.println("no");
}
}
}

其他问题:
1.windows10两边都需要开启SMB,否则,也是
 Connection reset的错误,和局域网防火墙是没有什么关系

 

 

2.github上找到的版本都是以2开头,官网上只有1开头的
两种版本方法调用不同
<dependency>
    <groupId>org.codelibs</groupId>
    <artifactId>jcifs</artifactId>
    <version>2.1.19</version>
</dependency>


posted @ 2021-07-23 11:25  机制的老鸟  阅读(2696)  评论(0编辑  收藏  举报