Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Mapping an unknown drive in Java

Posted on 2004-11-01
7
Medium Priority
?
359 Views
Last Modified: 2010-05-18
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:PASSWORD@REMOTEHOSTNAME/SHARENAME/myfile.txt");
      File fileTemp = new File(fileURI1);
      OutputStream out = new FileOutputStream(fileTemp);

I get the following exception
java.io.FileNotFoundException: \\USERID:PASSWORD@REMOTEHOSTNAME\SHARENAME\myfile.txt (The network path was not found)

WHat am I doing wrong?
0
Comment
Question by:gnazzoj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
7 Comments
 
LVL 3

Expert Comment

by:KeithWatson
ID: 12464278
This isn't good news I'm afraid...

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.
0
 
LVL 4

Expert Comment

by:aratani
ID: 12465093
Open up My Computer and try doing the following,

\\USERID:PASSWORD@REMOTEHOSTNAME\SHARENAME\

Tell me what it says.

AJ
0
 
LVL 1

Accepted Solution

by:
sbrown2k earned 2000 total points
ID: 12470577
We had to do this for a project that required the monitoring of drop files on about 50 different workstations, all running
various windows versions, with the shared directories password protected.

We tried the solution you proposed and had little luck.
However, we were 100% successfull using
JCIFS to initiate the SMB share and pass in the user name/password.

Its a java based library available from:

http://jcifs.samba.org/

Let me know if this helps!
0
 
LVL 1

Expert Comment

by:sbrown2k
ID: 12470638
It should solve your problems, and I forgot to mention the most important part ... it's open source and free.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Progress

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question