I am trying to use the SMBJ jar (https://github.com/hierynomus/smbj) to fetch a file from shared drive. I am able to connect to the shared disk. After the connect, any operation I perform is throwing exception.
For my shared drive location: //x.x.x.x/containing/folder/filename.txt, I am using the parameters as:
//SERVER_ADDRESS = x.x.x.x
//SHARE_NAME = /containing/folder/
//FILE_NAME = filename.txt
//LOCAL_PATH = "D:\\";
SMBClient client = new SMBClient();
try (Connection connection = client.connect(SERVER_ADDRESS)) {
AuthenticationContext ac = new AuthenticationContext(USERNAME, PASSWORD.toCharArray(), DOMAIN);
Session session = connection.authenticate(ac);
// Connect to Share
try (DiskShare share = (DiskShare) session.connectShare(SHARE_NAME)) {
Set<SMB2ShareAccess> s = new HashSet<>();
s.add(SMB2ShareAccess.ALL.iterator().next()); // this is to get READ only
com.hierynomus.smbj.share.File remoteSmbjFile = share.openFile(SHARE_NAME+FILE_NAME, EnumSet.of(AccessMask.GENERIC_READ), null, s, null, null);
java.io.File dest = new java.io.File(LOCAL_PATH + FILE_NAME);
try (InputStream is = remoteSmbjFile.getInputStream();
OutputStream os = new FileOutputStream(dest);) {
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
}
}
} catch (IOException e) {
e.printStackTrace();
LOGGER.error("", e);
return "ERROR";
} catch (Exception e) {
e.printStackTrace();
LOGGER.error("", e);
return "ERROR";
}
I am getting the exception as below. I think that I am not getting the right combination for the parameters.
com.hierynomus.mssmb2.SMBApiException: STATUS_INVALID_PARAMETER(3221225485/3221225485): Create failed for \containing\folder\
at com.hierynomus.smbj.share.Share.receive(Share.java:364)
at com.hierynomus.smbj.share.Share.sendReceive(Share.java:344)
at com.hierynomus.smbj.share.Share.createFile(Share.java:136)
at com.hierynomus.smbj.share.DiskShare.open(DiskShare.java:59)
at com.hierynomus.smbj.share.DiskShare.openDirectory(DiskShare.java:82)
at com.hierynomus.smbj.share.DiskShare.list(DiskShare.java:169)
at com.hierynomus.smbj.share.DiskShare.list(DiskShare.java:151)
I am unable to get what is wrong here. Can you please suggest what I am missing here.