Search code examples
javasmb

how to define path in SMB


I have a scenario where I need to send a file from my machine to some shared location. When I can see shared location on my machine (windows 7) is shown as N: drive.

the O/P for net use command to find its remote and I get it as \\smb\ds

I'm writing code to write the string to file in remote location i.e. N:\TESTING_GOING_ON\test.txt it goes like this,

String user = "abcd:XXXXX";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user);
String path = "smb//ds/TESTING_GOING_ON/test.txt";
SmbFile sFile = new SmbFile(path,auth);
try (SmbFileOutputStream sfos = new SmbFileOutputStream(sFile)) {
    sfos.write(str.getBytes());
    sfos.close();
}

using jcifs.smb.* But, for path I'm getting either no protocol defined or failed to connect.

So someone could please let me know the path I'm using is correct or not. If incorrect what how


Solution

  • The documentation seems pretty clear (though I haven't tested). The example format is

    smb://storage15/public/foo.txt
    

    so for you, that should be

    smb://smb/ds/TESTING_GOING_ON/test.txt
    

    Assuming your SMB server is actually named smb, which would be, interesting.