Reading a file from another machine on the network

Discussion in 'Java' started by mineshdesai@gmail.com, Mar 14, 2007.

  1. Guest

    Hello,

    I have a requirement in which i want to read a file from another
    machine in the network. And also the machine is password protected.

    Can any one help me out in this.

    I tried doing it in following way,

    URI uri = URI.create("file://9.182.198.145/shared");

    File file = new File(uri);

    As i excute this code i get an exception as:
    java.lang.IllegalArgumentException: URI has an authority component

    Can any one help me out in this.

    Thanks in Advance
     
    , Mar 14, 2007
    #1
    1. Advertising

  2. schrieb:
    > Hello,
    >
    > I have a requirement in which i want to read a file from another
    > machine in the network. And also the machine is password protected.


    Which protocol?

    >
    > Can any one help me out in this.
    >
    > I tried doing it in following way,
    >
    > URI uri = URI.create("file://9.182.198.145/shared");
    >
    > File file = new File(uri);
    >
    > As i excute this code i get an exception as:
    > java.lang.IllegalArgumentException: URI has an authority component


    Seems like the above is treated as UNC name which can't be used accross
    platforms. E. g. Linux would look for a file 'shared' in directory
    '9.182.198.145'.

    Under windows you might want to try
    "file://username:password@9.182.198.145/shared"

    but perhaps it's easier to mount the share via

    net use X: \\9.182.198.145\Shared <password> /user:<username>

    and then access the file via X: ;)

    Bye
    Michael
     
    Michael Rauscher, Mar 14, 2007
    #2
    1. Advertising

  3. Guest

    On Mar 14, 4:14 pm, Michael Rauscher <> wrote:
    > schrieb:
    >
    > > Hello,

    >
    > > I have a requirement in which i want to read a file from another
    > > machine in the network. And also the machine is password protected.

    >
    > Which protocol?
    >
    >
    >
    > > Can any one help me out in this.

    >
    > > I tried doing it in following way,

    >
    > > URI uri = URI.create("file://9.182.198.145/shared");

    >
    > > File file = new File(uri);

    >
    > > As i excute this code i get an exception as:
    > > java.lang.IllegalArgumentException: URI has an authority component

    >
    > Seems like the above is treated as UNC name which can't be used accross
    > platforms. E. g. Linux would look for a file 'shared' in directory
    > '9.182.198.145'.
    >
    > Under windows you might want to try
    > "file://username:passw...@9.182.198.145/shared"
    >
    > but perhaps it's easier to mount the share via
    >
    > net use X: \\9.182.198.145\Shared <password> /user:<username>
    >
    > and then access the file via X: ;)
    >
    > Bye
    > Michael


    Michael Thanks for reply,

    I will explain you the requirement,

    I have few machines on the network, i want to access a file under
    "shared" folder on the machine with i.p address as 9.182.198.145

    and all the systems have windows OS.

    One more thing i tried with following code and i got the same
    exception

    URI uri = URI.create("file://username:password@9.182.198.145/shared");

    File file = new File(uri);


    can you please help me out in this.

    Thanks
     
    , Mar 14, 2007
    #3
  4. schrieb:
    > On Mar 14, 4:14 pm, Michael Rauscher <> wrote:
    >> schrieb:
    >>
    >>> Hello,
    >>> I have a requirement in which i want to read a file from another
    >>> machine in the network. And also the machine is password protected.

    >> Which protocol?
    >>
    >>
    >>
    >>> Can any one help me out in this.
    >>> I tried doing it in following way,
    >>> URI uri = URI.create("file://9.182.198.145/shared");
    >>> File file = new File(uri);
    >>> As i excute this code i get an exception as:
    >>> java.lang.IllegalArgumentException: URI has an authority component

    >> Seems like the above is treated as UNC name which can't be used accross
    >> platforms. E. g. Linux would look for a file 'shared' in directory
    >> '9.182.198.145'.
    >>
    >> Under windows you might want to try
    >> "file://username:passw...@9.182.198.145/shared"
    >>
    >> but perhaps it's easier to mount the share via
    >>
    >> net use X: \\9.182.198.145\Shared <password> /user:<username>
    >>
    >> and then access the file via X: ;)
    >>
    >> Bye
    >> Michael

    >
    > Michael Thanks for reply,
    >
    > I will explain you the requirement,
    >
    > I have few machines on the network, i want to access a file under
    > "shared" folder on the machine with i.p address as 9.182.198.145
    >
    > and all the systems have windows OS.
    >
    > One more thing i tried with following code and i got the same
    > exception


    Sorry, I was wrong.

    Either you've got access to the Share, then you can simply use the UNC
    name (\\9.182.198.145\Shared). Otherwise I thinkg you'd have to map the
    Share to a drive letter or to have a look at http://jcifs.samba.org ;)

    Bye
    Michael
     
    Michael Rauscher, Mar 14, 2007
    #4
  5. Guest

    On Mar 14, 5:53 pm, Michael Rauscher <> wrote:
    > schrieb:
    >
    >
    >
    >
    >
    > > On Mar 14, 4:14 pm, Michael Rauscher <> wrote:
    > >> schrieb:

    >
    > >>> Hello,
    > >>> I have a requirement in which i want to read a file from another
    > >>> machine in the network. And also the machine is password protected.
    > >> Which protocol?

    >
    > >>> Can any one help me out in this.
    > >>> I tried doing it in following way,
    > >>> URI uri = URI.create("file://9.182.198.145/shared");
    > >>> File file = new File(uri);
    > >>> As i excute this code i get an exception as:
    > >>> java.lang.IllegalArgumentException: URI has an authority component
    > >> Seems like the above is treated as UNC name which can't be used accross
    > >> platforms. E. g. Linux would look for a file 'shared' in directory
    > >> '9.182.198.145'.

    >
    > >> Under windows you might want to try
    > >> "file://username:passw...@9.182.198.145/shared"

    >
    > >> but perhaps it's easier to mount the share via

    >
    > >> net use X: \\9.182.198.145\Shared <password> /user:<username>

    >
    > >> and then access the file via X: ;)

    >
    > >> Bye
    > >> Michael

    >
    > > Michael Thanks for reply,

    >
    > > I will explain you the requirement,

    >
    > > I have few machines on the network, i want to access a file under
    > > "shared" folder on the machine with i.p address as 9.182.198.145

    >
    > > and all the systems have windows OS.

    >
    > > One more thing i tried with following code and i got the same
    > > exception

    >
    > Sorry, I was wrong.
    >
    > Either you've got access to the Share, then you can simply use the UNC
    > name (\\9.182.198.145\Shared). Otherwise I thinkg you'd have to map the
    > Share to a drive letter or to have a look athttp://jcifs.samba.org;)
    >
    > Bye
    > Michael- Hide quoted text -
    >
    > - Show quoted text -


    Correct me if iam wrong...

    I have to Map the shared folder on my system then use the drive name
    give to the mapped folder in file constructor.

    Secondly,

    Shared folder is password protected, so now what should be done?

    Thanks
    Minesh
     
    , Mar 14, 2007
    #5
  6. Lew Guest

    wrote:
    > I have to Map the shared folder on my system then use the drive name
    > give to the mapped folder in file constructor.
    >
    > Secondly,
    >
    > Shared folder is password protected, so now what should be done?


    You have to provide the password when you mount the folder, so that part is
    already done. In effect, the drive mapping idea pushes the security problem
    out of Java space into user head space.

    -- Lew
     
    Lew, Mar 14, 2007
    #6
  7. Guest

    On Mar 14, 6:35 pm, Lew <> wrote:
    > wrote:
    > > I have to Map the shared folder on my system then use the drive name
    > > give to the mapped folder in file constructor.

    >
    > > Secondly,

    >
    > > Shared folder is password protected, so now what should be done?

    >
    > You have to provide the password when you mount the folder, so that part is
    > already done. In effect, the drive mapping idea pushes the security problem
    > out of Java space into user head space.
    >
    > -- Lew


    Is there any other alternative for this.
    That is,
    any alternative for mapping the folder into local drive.

    because if server changes then i need to again map the folder. Thats
    not feasible to do if i have to access many other machines.

    -- Minesh
     
    , Mar 14, 2007
    #7
  8. Chris Uppal Guest

    wrote:

    > Is there any other alternative for this.
    > That is,
    > any alternative for mapping the folder into local drive.


    jCIFS will probably do it.

    http://jcifs.samba.org/

    User-space implementation (in Java) of the SMB/CIFS network protocol which
    underlies Windows shared filesystems. Client side only (as far as I know).

    -- chris
     
    Chris Uppal, Mar 14, 2007
    #8
  9. wrote:
    > On Mar 14, 6:35 pm, Lew <> wrote:
    >> wrote:
    >>> I have to Map the shared folder on my system then use the drive name
    >>> give to the mapped folder in file constructor.
    >>> Secondly,
    >>> Shared folder is password protected, so now what should be done?

    >> You have to provide the password when you mount the folder, so that part is
    >> already done. In effect, the drive mapping idea pushes the security problem
    >> out of Java space into user head space.
    >>
    >> -- Lew

    >
    > Is there any other alternative for this.
    > That is,
    > any alternative for mapping the folder into local drive.
    >
    > because if server changes then i need to again map the folder. Thats
    > not feasible to do if i have to access many other machines.


    I've already mentioned an alternative: http://jcifs.samba.org.

    Bye
    Michael
     
    Michael Rauscher, Mar 14, 2007
    #9
  10. Guest

    On Mar 14, 11:30 pm, "Chris Uppal" <-
    THIS.org> wrote:
    > wrote:
    > > Is there any other alternative for this.
    > > That is,
    > > any alternative for mapping the folder into local drive.

    >
    > jCIFS will probably do it.
    >
    > http://jcifs.samba.org/
    >
    > User-space implementation (in Java) of the SMB/CIFS network protocol which
    > underlies Windows shared filesystems. Client side only (as far as I know).
    >
    > -- chris


    Hey guys thanks for help, i was able to do it by using jCIFS

    Bye
    Minesh Desai
     
    , Mar 15, 2007
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tola
    Replies:
    29
    Views:
    1,049
    Mark McIntyre
    Dec 28, 2003
  2. Nico Grubert
    Replies:
    1
    Views:
    2,639
    Markus Rosenstihl
    Sep 21, 2005
  3. Steve Holden
    Replies:
    0
    Views:
    424
    Steve Holden
    Sep 21, 2005
  4. harijay
    Replies:
    2
    Views:
    504
    Gabriel Genellina
    Feb 19, 2009
  5. PerlFAQ Server
    Replies:
    0
    Views:
    142
    PerlFAQ Server
    Apr 9, 2011
Loading...

Share This Page