jcifs.smb.SmbAuthException:登录失败:未知用户名或密码错误。
Posted
技术标签:
【中文标题】jcifs.smb.SmbAuthException:登录失败:未知用户名或密码错误。【英文标题】:jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad password. 【发布时间】:2012-07-08 13:25:18 【问题描述】:计划使用 jcifs 从 Ubuntu 中的 Java 中通过 Windows 读取文件。尝试使用以下简单方法:
String user = "mydomain;myuser:mypassword";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user);
SmbFile remotefile = new SmbFile("smb://myserver/myfolder/myfile.jar",auth);
知道服务器工作正常并且登录值正确,我得到的只是登录失败,这可能是什么问题?
【问题讨论】:
返回的登录失败代码是什么。 JCIFS 错误代码列表jcifs.samba.org/ntstatus.txt 嘿,你解决了这个问题吗?如果怎么解决?我有同样的问题。 【参考方案1】:不确定您是否可以使用它。
但是在经历了很多痛苦和痛苦之后,我认为NtlmPasswordAuthentication
调用必须包含域。
因此,如果您使用发布的代码@user717630,您只需将NtlmPasswordAuthentication
调用更改为:
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("mydomain",user, pass);
【讨论】:
【参考方案2】:以下程序验证并在受保护的共享文件夹中写入文件:
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;
希望这是有用的。期待对此的反馈。
谢谢,
元帅。
【讨论】:
嘿,我尝试了同样的方法,但我收到一条错误消息,提示用户名无效或密码错误。我已检查我的用户名、密码和域是否正确。【参考方案3】:这是为您提供的解决方案,我稍微更改了代码以使其更具可读性。 创建一个共享文件夹并将共享文件夹名称放在下面的变量中(sharedFolder) 如果您不知道如何在 Windows 上创建共享文件夹...一如既往地使用 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);
【讨论】:
【参考方案4】:尝试使用 IP 地址而不是服务器名称,看看它是否连接。它可能无法解析服务器名称。
【讨论】:
【参考方案5】:评论“peterb”的回答:“...调用必须包含域...”
我发现在我的情况下 NtlmPasswordAuthentication( "domain", "username", "password" ) 需要这样的输入: domain 是具有共享路径的长域:\xxxx.domain.xxxx.com\path。 username 是带有域的用户名:域\用户名。 密码 = 密码。
我希望这会对某人有所帮助。
BEM
【讨论】:
【参考方案6】:jcifs-ng-2.1.6.jar 中有几个构造函数。
我对该问题的解决方案是为来宾(匿名)用户使用默认构造函数
auth = baseCxt.withCredentials(new NtlmPasswordAuthenticator());
【讨论】:
以上是关于jcifs.smb.SmbAuthException:登录失败:未知用户名或密码错误。的主要内容,如果未能解决你的问题,请参考以下文章