gnazzoj
asked on
Mapping an unknown drive in Java
I want to connect to a remote computer on the network that is NOT currently Drive mapped to my local computer.
I then want to copy a file from my local computer to the remote computer.
The code I have been trying to use is this:
URI fileURI1 = new URI("file:////USERID:PASSW ORD@REMOTE HOSTNAME/S HARENAME/m yfile.txt" );
File fileTemp = new File(fileURI1);
OutputStream out = new FileOutputStream(fileTemp) ;
I get the following exception
java.io.FileNotFoundExcept ion: \\USERID:PASSWORD@REMOTEHO STNAME\SHA RENAME\myf ile.txt (The network path was not found)
WHat am I doing wrong?
I then want to copy a file from my local computer to the remote computer.
The code I have been trying to use is this:
URI fileURI1 = new URI("file:////USERID:PASSW
File fileTemp = new File(fileURI1);
OutputStream out = new FileOutputStream(fileTemp)
I get the following exception
java.io.FileNotFoundExcept
WHat am I doing wrong?
Open up My Computer and try doing the following,
\\USERID:PASSWORD@REMOTEHO STNAME\SHA RENAME\
Tell me what it says.
AJ
\\USERID:PASSWORD@REMOTEHO
Tell me what it says.
AJ
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It should solve your problems, and I forgot to mention the most important part ... it's open source and free.
I tried to do something similar a number of months ago and came to the ultimate conclusion that it couldn't be done. In looking up the specification of the URI, it's not clear what's stated; it says file URIs are similar to FTP URIs, but no specific mention is made of usernames and passwords. I think it's legal URI syntax, but I don't think it's implemented in the JDK (although I couldn't confirm this in any other way other than the fact that it didn't work). I tried three different approaches; all failed. The only way I could get it to work (which I think you've hinted at already), is that if you map a drive to the remote location, it works - even if you use the full UNC path rather than the mapped drive. I guess Windows must automatically be passing the credentials.
Sorry that's of little help, but unless someone else can come up with an idea that works, at least it may save you additional effort. I wound up placing an FTP server on the target machine and just using FTP to access the file.
Keith.