首页 > 其他 > 详细

jcifs使用踩坑

时间:2021-07-23 16:10:03      阅读:23      评论:0      收藏:0      [点我收藏+]

工作需求要远程控制公共盘,百度了一圈发现能用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.还有19版本的jcifs,和17不同的是,之前的方法都被弃用,新方法教程很少,不知道如何使用
<dependency>
    <groupId>org.codelibs</groupId>
    <artifactId>jcifs</artifactId>
    <version>2.1.19</version>
</dependency>


jcifs使用踩坑

原文:https://www.cnblogs.com/jzdln/p/15048107.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!