0

I have a network share \\host-IP\folder\subFolder. I want to open this from java where username and password should be prompted in connect to window. I wanted to achieve this in both MAC and windows. Any help ?

EDIT

IN windows : using explorer command i could acheive upto the root of the shared path. If i give sub folders it says the path does not exists. But if i try the same from run window (windows+R) it works (it prompts for the username and password). But i do not know how to call the same from java.

Thanks in advance

Samrat
  • 367
  • 2
  • 4
  • 21

2 Answers2

0

Have a look at this thread.

Write I/O file to shared network drive using credentials

Providing that you write the UI that prompts the user to enter authentication credentials yourself, it should be possible to access the share using the CIFS library. However, do make sure to take a look at my comment about having the OS take care of the authentication to the network share transparently to your application.

Edit: Using CIFS you should of course write the network path samba style, i.e. smb://host-IP/folder/subFolder

Community
  • 1
  • 1
dkateros
  • 1,574
  • 10
  • 14
  • I want the windows OS to prompt for connect to window. If i use `Runtime.getRuntime.exec("explorer \\\\host-IP\\folder")` it prompts for username and password. If i use `Runtime.getRuntime.exec("explorer \\\\host-IP\\folder\\subfolder")` it says the error `network path does not exist`. – Samrat Dec 11 '12 at 08:56
0

This may help you

 Runtime rt = Runtime.getRuntime();
 Process pr = rt.exec("explorer "+"\\\\"+"<SERVER>"+"\\"+"<FOLDER>"+"\\"+"<SUB FOLDER>");
Shantanu Banerjee
  • 1,417
  • 6
  • 31
  • 51
  • no luck with this. Please see my comment for dkateros answer. – Samrat Dec 11 '12 at 09:19
  • @Samrat can you post your command and error please!! In my case it works fine – Shantanu Banerjee Dec 11 '12 at 09:21
  • when i run ` Runtime rt = Runtime.getRuntime(); Process pr = rt.exec("explorer "+"\\\\"+"xxx.xxx.xxx.xxx"+"\\"+"Folder"); ` without sub folder it prompts me for username and password and if i run with subfolder ` Runtime rt = Runtime.getRuntime(); Process pr = rt.exec("explorer "+"\\\\"+"xxx.xxx.xxx.xxx"+"\\"+"Folder"+"\\"+"SUB");` it says the path does not exist or is not a directory. – Samrat Dec 11 '12 at 09:23
  • Check weather its working in dos or not, open cmd and put this command – Shantanu Banerjee Dec 11 '12 at 09:25
  • In dos it is not working. But if i try the same from start-run without explorer by providing network folder upto sub `\\xx.xx.xx.xx\folder\sub` it prompts for the username and password – Samrat Dec 11 '12 at 09:30
  • enter those username and password, and check it remember. Then try the command – Shantanu Banerjee Dec 11 '12 at 09:34
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/20932/discussion-between-samrat-and-shantanu-banerjee) – Samrat Dec 11 '12 at 09:36