jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad password.
Asked Answered
A

6

8

planning to read a file over a Windows from Ubuntu in Java using jcifs.Tried a simple approach using:

String user = "mydomain;myuser:mypassword";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user);
SmbFile remotefile = new SmbFile("smb://myserver/myfolder/myfile.jar",auth);

Knowing that the server works and the login values are correct,all i get is a logon failure,what could be the problem here?

Av answered 9/7, 2012 at 6:35 Comment(2)
what is the login failure code that is getting returned. For list of JCIFS error codes jcifs.samba.org/ntstatus.txtFad
Hey did u resolve this issue?if how? i have the same issue.Zoonosis
T
9

Not sure if you got this to work. But after much pain and anguish, I figured the NtlmPasswordAuthentication call must include the domain. So if you're using the code @user717630 posted, you'll just have to change the NtlmPasswordAuthentication call to: NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("mydomain",user, pass);

Tafilelt answered 4/11, 2012 at 14:12 Comment(0)
A
3

The following program authenticates and writes a file on the protected share folder:

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;
}
}

Hope this is useful. Expecting feedback on this.

Thanks,

Marshal.

Agle answered 11/12, 2012 at 13:8 Comment(1)
Hey, I tried the same but I get an error saying invalid user name or bad password. I have checked my user name, password and domain are correct.Thermosetting
L
2

Here is the solution for you I changed the code a little to make it more readable. Create a shared folder and put the shared folder name in the below variable(sharedFolder) if you don't know how to create shared folder on windows ...use google as always. Also, make sure this user that you are using has at least read access to that folder.

    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);
Ligniform answered 19/10, 2012 at 20:20 Comment(0)
F
1

Try using IP address instead of server name and see if it connects or not. It probably cannot resolve the server name.

Footstall answered 22/7, 2012 at 7:33 Comment(0)
R
1

Comment to "peterb"s answer: "...call must include the domain..."

I figured out that in my case the NtlmPasswordAuthentication( "domain", "username", "password" ) needs its inputs like this: domain is the long domain with path to the share:\xxxx.domain.xxxx.com\path. username is the username with domain: domain\username. password = password.

I hope this will help some one.

BEM

Radiothermy answered 7/12, 2017 at 9:20 Comment(0)
L
0

There are several constructors in jcifs-ng-2.1.6.jar.
My solution for that problem was using a default constructor for guest (anonymous) user
auth = baseCxt.withCredentials(new NtlmPasswordAuthenticator());

Lattie answered 15/8, 2021 at 15:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.