Solved

Mapping an unknown drive in Java

Posted on 2004-11-01
355 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
Question by:gnazzoj
    4 Comments
     
    LVL 3

    Expert Comment

    by:KeithWatson
    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
    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:
    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
    It should solve your problems, and I forgot to mention the most important part ... it's open source and free.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    Problem to refer to cell 8 58
    Safe way to use a password in a bat or cmd file? 8 43
    allStar challenge 1 10
    endX challenge 2 13
    This is an explanation of a simple data model to help parse a JSON feed
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    877 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now