Closed umangsamani closed 5 years ago
LOGON_FAILURE means that the server refused the credentials. I guess you should use Administrator
as username. not .\administrator
. Either that or your password is bad.
I was wondering that this should be something silly. Thank you.
Why it is showing com.hierynomus.mssmb2.SMBApiException: STATUS_LOGON_FAILURE (0xc000006d): Even i am giving right domian / password / username I have tried it with both UPPERCASE and lowercase
Does SMBJ can be tested on my own laptop by making folder sharable
Please help urgent required
public class smbjcls { private static final String SHARE_DOMAIN = " anchor.abcdef.com"; private static final String SHARE_USER = "pqr.xyz"; private static final String SHARE_PASSWORD = "SmsStadium302017"; private static final String SHARE_SRC_DIR = "E:\share\source"; private static final String SHARE_DST_DIR = "E:\reciever\destination";
public static void main(String[] args) {
SmbConfig config = SmbConfig.builder().withTimeout(1200, TimeUnit.SECONDS)
.withTimeout(1200, TimeUnit.SECONDS)
.withSoTimeout(1800, TimeUnit.SECONDS)
.build();
SMBClient client = new SMBClient(config);
try {
Connection connection = client.connect("192.***.*.**"); // For example: 123.123.123.123
System.out.println("Connection is created1");
AuthenticationContext ac = new AuthenticationContext(SHARE_USER, SHARE_PASSWORD.toCharArray(), SHARE_DOMAIN);
System.out.println("AuthenticationContext is created2");
Session session = connection.authenticate(ac); //The java string toCharArray() method converts the given string into a sequence of characters.
System.out.println("Session is created3");
// Connect to a shared folder
DiskShare share = (DiskShare) session.connectShare(SHARE_SRC_DIR);
//Connect to a share on the remote machine over the authenticated session.
System.out.println("Session is created4");
String folder = SHARE_SRC_DIR + SHARE_DST_DIR;
String dstRoot = "The local folder path to save"; // For example: D:/smd2/
for (FileIdBothDirectoryInformation f : share.list(SHARE_DST_DIR, "*.mp4")) {
String filePath = folder + f.getFileName();
String dstPath = dstRoot + f.getFileName();
FileOutputStream fos = new FileOutputStream(dstPath);
BufferedOutputStream bos = new BufferedOutputStream(fos);
if (share.fileExists(filePath)) {
System.out.println("Downloading file:" + f.getFileName());
File smbFileRead = share.openFile(filePath, EnumSet.of(AccessMask.GENERIC_READ), null, SMB2ShareAccess.ALL, SMB2CreateDisposition.FILE_OPEN, null);
InputStream in = smbFileRead.getInputStream();
byte[] buffer = new byte[4096];
int len = 0;
while ((len = in.read(buffer, 0, buffer.length)) != -1) {
bos.write(buffer, 0, len);
}
bos.flush();
bos.close();
System.out.println("File Download Successful");
System.out.println("==========================");
} else {
System.out.println("File does not exist");
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (client != null) {
client.close();
}
}
}
}
Getting started with SMBJ, and trying to execute the first example and getting Authentication failed error.
Use Case : I am simply trying to connect to a fileshare which has SMB1 disabled. For which I am providing below details: Server name - "0.0.0.0"
domain - null
Username - ".\administrator"
Password - "Password".
Getting this message for Line # 2 - Successfully connected to:0.0.0.0
The very next line is to authenticate, and that is where it is throwing the exception: _Exception in thread "main" com.hierynomus.mssmb2.SMBApiException: STATUS_LOGONFAILURE (0xc000006d): Authentication failed for '.\administrator' using com.hierynomus.smbj.auth.NtlmAuthenticator@5faeada1 at com.hierynomus.smbj.connection.Connection.authenticate(Connection.java:182) at Main.main(Main.java:24)
Ultimately, I just want to list the files/folders under a share ("0.0.0.0\d$\SMBFolder") Any help will be appreciated.