Write I/O file to shared network drive using credentials

前端 未结 2 1663
甜味超标
甜味超标 2020-11-29 08:59

I want to drop a .txt file on a shared network drive. The path is a map on a networkdrive which requires credentials (login and password). Can i pass these parameters using

2条回答
  •  醉话见心
    2020-11-29 09:27

    No. Use java CIFS Client library. you can connect remote windows machine through java. example -

    String user = "user:password";
    NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user);
    String path = "smb://my_machine_name/D/MyDev/test.txt";
    SmbFile sFile = new SmbFile(path, auth);
    SmbFileOutputStream sfos = new SmbFileOutputStream(sFile);
    sfos.write("Test".getBytes());
    sfos.close();
    

    Thanks

    EDIT: JCIFS only supports the unsecure SMB1 protocol and has been in maintainance mode for some years. Use jcifs-ng for SMB2/SMB3 support which is required from Windows 10.

提交回复
热议问题