SMBJ unable to write file

Viewed 259

Unable to write file to the sahred folder, i get the exception.

com.hierynomus.mssmb2.SMBApiException: STATUS_ACCESS_DENIED (0xc0000022): Create failed for \10.x.x.x\XYZZZZZZ\xyz.txt

I have verified that this account has complete access to that shared folder

// connection params
static String sambaDomain = null;
static String sambaUsername = "user123";
static String sambaPass = "pwd";
static String sambaIP = "10.x.x.x";
static String sambaSharedPath = "XYZZZZZZ";

public static void main(String[] args) {

    SMBClient client = new SMBClient();
    Connection connection = null;
    try {
        byte[] bytes = Files.readAllBytes(Paths.get("C:\\Users\\xxxx\\testdoc2.pdf"));
        connection = client.connect(sambaIP);

        Session session = connection.authenticate(new AuthenticationContext(sambaUsername, sambaPass.toCharArray(), sambaDomain));
        DiskShare share = (DiskShare) session.connectShare(sambaSharedPath);


        File f = share.openFile("xyz.txt",
                EnumSet.of(AccessMask.FILE_WRITE_DATA),
                EnumSet.of(FileAttributes.FILE_ATTRIBUTE_NORMAL),
                SMB2ShareAccess.ALL,
                SMB2CreateDisposition.FILE_CREATE,
                EnumSet.of(SMB2CreateOptions.FILE_DIRECTORY_FILE));

        OutputStream os = f.getOutputStream();

        os.write(bytes);
        os.flush();
        os.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
0 Answers
Related