Access to file using Java with Samba JCIFS

前端 未结 2 487
情深已故
情深已故 2020-11-27 15:44

I have a question about accessing file with Samba JCIFS.

So there is a server I want to access, let\'s call it server.unv.edu and the workgroup is WKGRP.

There

2条回答
  •  难免孤独
    2020-11-27 16:03

    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 !");
    

提交回复
热议问题