我想将共享的Windows文件夹复制到linux(在VM上运行)。我正在使用JCIFS SMB Framework
代码
package pkg;
import java.net.MalformedURLException;
import jcifs.smb.*;
public class FolderCopy {
/**
* @param args
*/
public static void main(String[] args) {
try{
//This is windows shared folder path
String urlToBackUpFile = "smb://ip/Share";
System.out.println("smb folder of source file" + urlToBackUpFile);
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("domain", "username", "password");
SmbFile dir = new SmbFile(urlToBackUpFile, auth);
System.out.println(dir.getDate());
//This is linux path where I want to copy.
SmbFile dest = new SmbFile ("file:///home/cloudera/Desktop/Test",auth);
dir.copyTo(dest);
// TODO Auto-generated method stub
}
catch (MalformedURLException e1) {
e1.printStackTrace();
}
catch (SmbException e1) {
e1.printStackTrace();
}
}
}
异常
jcifs.smb.SmbException: Failed to connect to server
java.net.UnknownHostException: ..__MSBROWSE__.<01>
at jcifs.netbios.NbtAddress.doNameQuery(NbtAddress.java:308)
at jcifs.netbios.NbtAddress.getByName(NbtAddress.java:413)
at jcifs.netbios.NbtAddress.getByName(NbtAddress.java:394)
at jcifs.smb.SmbFile.getAddress(SmbFile.java:749)
at jcifs.smb.SmbFile.connect(SmbFile.java:790)
at jcifs.smb.SmbFile.connect0(SmbFile.java:767)
at jcifs.smb.SmbFile.copyTo(SmbFile.java:2112)
at pkg.FolderCopy.main(FolderCopy .java:22)
at jcifs.smb.SmbFile.connect0(SmbFile.java:769)
at jcifs.smb.SmbFile.copyTo(SmbFile.java:2112)
at pkg.FolderCopy .main(FolderCopy .java:22)
我提到了这个:How to copy file from smb share to local drive using jcifs in Java?