需求:内网操作,从 winserver 服务器A 下载文件到 linux 服务器B,用Java实现,Java程序部署在服务器B
思路:使用jcifs框架的smb协议
操作:
1、配置jar包
<!-- https://mvnrepository.com/artifact/org.samba.jcifs/jcifs -->
<dependency>
<groupId>org.samba.jcifs</groupId>
<artifactId>jcifs</artifactId>
<version>1.3.3</version>
</dependency>
2、写代码
服务器A的内网地址 "10.101.2.110", 用户名是"tsadm",域是"yn",密码是 "Test123456"
/**
* 下载共享目录文件到本地
*
* @param romoteFile 远程的文件地址 例如 projectText\HC96\1003\159773445796954466.doc
* @param fileTempName 本地暂存文件名 uuid.type
*/
private Boolean downWindowsFile(String romoteFile, String fileTempName) {
//获取文件
InputStream inDown = null;
ByteArrayOutputStream outDown = null;
FileOutputStream fileOutputStream = nul

本文介绍了一个在内网环境中,如何使用Java和jcifs框架通过smb协议从Windows服务器A下载文件到Linux服务器B的过程。关键在于正确配置NtlmPasswordAuthentication,包括服务器地址、用户名、密码以及域信息,避免因忽略域导致的登录失败问题。
最低0.47元/天 解锁文章
1171

被折叠的 条评论
为什么被折叠?



