jcifs.smb.SmbAuthException:登录失败:未知的用户名或密码错误。
规划使用jcifs.Tried用一个简单的方法来读取从上一个Ubuntu的Windows中的文件在Java中:jcifs.smb.SmbAuthException:登录失败:未知的用户名或密码错误。
String user = "mydomain;myuser:mypassword";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user);
SmbFile remotefile = new SmbFile("smb://myserver/myfolder/myfile.jar",auth);
即使知道服务器的工作原理和登录值是正确的,我得到的是登录失败,这里可能是什么问题?
尝试使用IP地址而不是服务器名称,并查看它是否连接。它可能无法解析服务器名称。
这是您的解决方案我稍微更改了代码以使其更具可读性。 如果您不知道如何在Windows上创建共享文件夹,请创建一个共享文件夹,并将共享文件夹名称放在下面的变量(sharedFolder) 中...一如既往地使用google。另外,请确保您使用的用户至少具有对该文件夹的读取权限。
String user = "your_user_name";
String pass ="your_pass_word";
String sharedFolder="shared";
String path="smb://ip_address/"+sharedFolder+"/myfile.jar";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("",user, pass);
SmbFile smbFile = new SmbFile(path,auth);
SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFile);
不知道你是否有这个工作。 但经过很多痛苦和痛苦之后,我觉得NtlmPasswordAuthentication
电话必须包含域名。 所以,如果你使用的代码@ user717630发布后,您只需要改变NtlmPasswordAuthentication
呼吁: NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("mydomain",user, pass);
这真的很有帮助..谢谢你 – 2014-11-07 10:06:05
以下程序验证和受保护的共享文件夹写入一个文件:
import java.util.Properties;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileOutputStream;
public class ProtectFolderTest {
private String USER_NAME = null;
private String PASSWORD = null;
private String DOMAIN = null;
private String NETWORK_FOLDER = null;
public static void main(String args[]) {
try {
String fileContent = "Hi, This is the SmbFile.";
new ProtectFolderTest().copyFiles(fileContent, "SmbFile1.text");
} catch (Exception e) {
System.err.println("Exception caught. Cause: " + e.getMessage());
}
}
public boolean copyFiles(String fileContent, String fileName) {
boolean successful = false;
String path = null;
NtlmPasswordAuthentication auth = null;
SmbFile sFile = null;
SmbFileOutputStream sfos = null;
try {
USER_NAME = "username";
PASSWORD = "password";
DOMAIN = "domain";
NETWORK_FOLDER = "smb://machineName/network_folder/";
auth = new NtlmPasswordAuthentication(
DOMAIN, USER_NAME, PASSWORD);
path = NETWORK_FOLDER + fileName;
sFile = new SmbFile(path, auth);
sfos = new SmbFileOutputStream(sFile);
sfos.write(fileContent.getBytes());
successful = true;
System.out.println("File successfully created.");
} catch (Exception e) {
successful = false;
System.err.println("Unable to create file. Cause: "
+ e.getMessage());
}
return successful;
}
}
希望这是有用的。期待对此的反馈。
谢谢,
元帅。
评论为“peterb”回答是:“......调用必须包含域......”
我想通了,在我的情况下,NtlmPasswordAuthentication(‘域’,‘用户名’,‘密码’ )需要如下输入: 域是具有共享路径的长域:\ xxxx.domain.xxxx.com \ path。 用户名是域名为domain \ username的用户名。 密码=密码。
我希望这对一些人有帮助。
BEM
什么是返回的登录失败代码。对于JCIFS错误代码列表http://jcifs.samba.org/ntstatus.txt – 2012-07-23 06:29:05
嘿,你解决了这个问题?如果如何?我有同样的问题。 – mdp 2012-10-08 19:03:51