"access to file using java with samba jcifs" Code Answer


you are making this harder than it should be. please follow the below steps and make sure the shared folder you are creating has write access for this user you are using.

  1. download the jar file http://jcifs.samba.org/ (there is only one jar file)
  2. copy and paste the below code with your information for user name, password and shared folder and that's all you need

i was running this on linux and wanted to write to a windows box so you want to create a shared folder and put the shared folder name in the below variable if you don't know how to create shared folder on windows ...use google as always

    string user = "your_user_name";
    string pass ="your_pass_word";

    string sharedfolder="shared";
    string path="smb://ip_address/"+sharedfolder+"/test.txt";
    ntlmpasswordauthentication auth = new ntlmpasswordauthentication("",user, pass);
    smbfile smbfile = new smbfile(path,auth);
    smbfileoutputstream smbfos = new smbfileoutputstream(smbfile);
    smbfos.write("testing....and writing to a file".getbytes());
    system.out.println("completed ...nice !");
By Hermanter on April 27 2022
Only authorized users can answer the Search term. Please sign in first, or register a free account.