使用jcifs在smb目录中连接错误

时间:2013-12-09 21:14:30

标签: java smb

如果我尝试

NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("cabanellos.local","deivisson.sedrez", "passs");
String path = "smb://fsct/scanpr$/test.txt";`
SmbFile sFile2 = new SmbFile(path, auth);    `

它连接并创建一个文件,但如果我尝试:

NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("cabanellos.local",  "deivisson.sedrez", "passs");
String path = "smb://fsct/scanpr$/"; 
SmbFile sFile2 = new SmbFile(path, auth);    
SmbFile[] varTeste = dir.listFiles();    
for(int i=0;i<varTeste.length;i++){
    if(varTeste[i].isFile()){                                    
         //site = new URL((Pasta_Financeiro + varTeste[i].getName()).toString()); 
         SmbFile dest = new SmbFile ("file:///"+Pasta_Financeiro + varTeste[i].getName());
         dir.copyTo(dest);
    }
}

我收到此异常“登录失败:未知用户名或密码错误。”但一切都正确

为什么会这样?

2 个答案:

答案 0 :(得分:0)

您可能应该使用“smb://”+ Pasta_Financeiro而不是“file:///”+ Pasta_Financeiro

答案 1 :(得分:0)

我用

SmbFile remoteFile = new SmbFile("smb://...") OutputStream os = new FileOutputStream("/path/to/local/file"); InputStream is = remoteFile.getInputStream(); int bufferSize = 1024; byte[] b = new byte[bufferSize]; int noOfBytes = 0; while( (noOfBytes = is.read(b)) != -1 ) { os.write(b, 0, noOfBytes); } os.close(); is.close();

dir.copyTo(dest);

及其作品

求助