报错信息:No more connections can be made to this remote computer at this time because there are already as many connections as the computer can accept.
准备jar包(以gradle为例):
compile group: 'org.springframework.integration', name: 'spring-integration-smb', version: '1.0.0.RELEASE'
compile group: 'org.springframework.integration', name: 'spring-integration-file', version: '5.0.4.RELEASE'
compile group: 'org.springframework.integration', name: 'spring-integration-stream', version: '5.0.4.RELEASE'
compile group: 'org.codelibs', name: 'jcifs', version: '1.3.18.3'
以移动远程电脑//192.168.6.133/share文件下的文件为例子:
public void goTest() {
SmbSession session=null;
String ip = "192.168.6.133";
String directory = "share";
String userName="lzc";
String pwd = "1";
String rootURL = "//"+ ip +"/"+ directory +"/";
/*Config.setProperty("jcifs.smb.client.soTimeout", "100000");//*/
try {
SmbShare share=new SmbShare("smb://" + userName +":"+ pwd +"@"+ ip +"/share/");
session=new SmbSession(share);
String backUp=rootURL +"backUp/";
if(!session.exists(backUp)){
session.mkdir(backUp);
}
for (String name : share.list()){
System.out.println(name);
SmbFile smbForm=session.createSmbFileObject(rootURL + name);
if(smbForm.isDirectory()){
continue;
}
SmbFile smbBackUp = session.createSmbDirectoryObject(backUp + name);
smbForm.copyTo(smbBackUp);
smbForm.delete();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
session.close();
}
}