0

I'm writing an Android asynctask which needs to write to an SMB share using JCIFS. Before attempting the write, I'd like to check whether the SMB folder has write permissions, and display a message to the user if not. Ideally I'd like to do this without actually writing a file to the destination. Does anyone know how/if this would be possible?

Ian M
  • 567
  • 8
  • 33

2 Answers2

0

Try this.

static final String USER_NAME = "Username";
static final String PASSWORD = "Password";
static final String DOMAIN = "XYZ";    

static final String NETWORK_FOLDER = "smb://ip-address/Folder-Path/";
try{
    String fileContent = "This is a test file";
    String fileName = "test_File.txt"
    NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(DOMAIN,USER_NAME, PASSWORD);
    String path = NETWORK_FOLDER + fileName;
    System.out.println("Path: " +path);

    SmbFile sFile = new SmbFile(path, auth);
    SmbFileOutputStream sfos = new SmbFileOutputStrea(sFile);
    sfos.close();
    sfos.write(fileContent.getBytes());
}catch (Exception e) {
    e.printStackTrace();
}
vicky
  • 33
  • 6
0

You can use SmbFile.canWrite() method to check if user have write permission in particular folder. Check below API documentation.

https://jcifs.samba.org/src/docs/api/jcifs/smb/SmbFile.html#canWrite()

Vaibhav Dwivedi
  • 115
  • 1
  • 3
  • 8