hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
713 stars 180 forks source link

SMB Access Denied #577

Closed Zibeug closed 4 years ago

Zibeug commented 4 years ago

Hello,

I got a problem with SMBJ when I'd use method .openFile(). I have always a Exception : ACCESS_DENIED.

I just want to read the file and save into a class.

`public class LoaderXML extends AsyncTask <String, Void, String>{ private SMBClient smbClient; private Connection connection; private AuthenticationContext ac; private Session session; private ConnectionInfo connectionInfo; private File file;

@Override
protected String doInBackground(String... strings) {
    smbClient = new SMBClient();
    try{
        connection = smbClient.connect("xxx.xxx.xxx.xxx", 445);
        ac = new AuthenticationContext("user", "xxxxxxxx".toCharArray(), "zibeug.internet-box.ch");
        session = connection.authenticate(ac);
        connectionInfo = session.getConnection().getConnectionInfo();
        DiskShare share = (DiskShare) session.connectShare("shareDiplome");
        Set<SMB2ShareAccess> s = new HashSet<>();
        s.add(SMB2ShareAccess.ALL.iterator().next());
        file = share.openFile("2020 05 11-0101 - Export_Checks.xml", EnumSet.of(AccessMask.GENERIC_READ), null, s, null, null);
        OutputStream outputStream = file.getOutputStream();
    }
    catch(IOException e){
        Log.i("TASK", "SMB: " + e.getMessage());
    }
    catch(Exception e) {
        Log.i("TASK", "SMB:" + e.getMessage());
    }

    return connectionInfo.getServerName();
}

@Override
protected void onPostExecute(String aVoid) {
    Log.i("TASK", aVoid);
}

}`

The configuration of my server is very simple, It's a windows server with an Active Directory and all user can read the file.

Can you maybe help me ?

Thanks and see you

andershermansen commented 4 years ago

Where is the exception coming from? Maybe show the full exception outout.

Also try: file = share.openFile("2020 05 11-0101 - Export_Checks.xml", EnumSet.of(AccessMask.GENERIC_READ), null, SMB2ShareAccess.ALL, SMB2CreateDisposition.FILE_OPEN, null);

Zibeug commented 4 years ago

Worked perfectly thanks !