How to access to a remote host?

Discussion in 'Java' started by alfredo.amato@gmail.com, Mar 22, 2006.

  1. Guest

    Hi to all!
    I'm new of Java and I'm trying to develope some application to improve
    myself.
    I have just built a simple application that, by class File(), displays
    content of my (local) file system..
    C:\
    C:\Folder1
    C:\Folder2
    ....
    ....
    C:\FolderN

    Now, I'm trying to access to an host on the local net to do the same
    but I don't know
    from where I have to start... I read about URI but I ask you.. Is it
    need? What must I use?
    Thank you very much in advance for help.
    Alfredo
     
    , Mar 22, 2006
    #1
    1. Advertising

  2. Carl Guest

    Alfredo,

    If you want to try to access a network share and know the UNC path, you
    can simply use the java.io.File object to get a list of the share
    directory contents.

    For example, suppose your server is name "myserver" and the share is
    "myshare"...

    // the unc path is '\\myserver\myshare\', the '\' should be escaped in
    the string.
    final String uncPath = "\\\\myserver\\myshare\\";
    File f = new File(uncPath);
    if (f.isDirectory()) {
    String[] listing = f.list();
    for (int x=0; x<listing.length; x++){
    System.out.println(listing[x]);
    }
    }
     
    Carl, Mar 22, 2006
    #2
    1. Advertising

  3. wrote:
    > I'm new of Java and I'm trying to develope some application to improve
    > myself.
    > I have just built a simple application that, by class File(), displays
    > content of my (local) file system..

    ....
    > Now, I'm trying to access to an host on the local net to do the same
    > but I don't know from where I have to start...
    >

    If you're wanting a general way of reading files on a remote machine
    without using a share, you need the write a server to run on the remote
    machine and a client to run on your local machine. You use the Socket
    class to allow the client to talk to the server.

    This is a big topic: before tackling it you need to know a bit about
    TCP/IP networks and the Sockets concept in order to understand what the
    Socket class methods do.

    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
     
    Martin Gregorie, Mar 23, 2006
    #3
  4. Alf_Italy Guest

    Thank you Carl!!! your solution seems working...but..It requires a
    previous access to the server...
    Do you know if there's a way to pass credentials as argument in the
    uncPath???
     
    Alf_Italy, Mar 23, 2006
    #4
  5. Carl Guest

    Alf_Italy wrote:
    > Thank you Carl!!! your solution seems working...but..It requires a
    > previous access to the server...
    > Do you know if there's a way to pass credentials as argument in the
    > uncPath???


    Alfredo,

    That is a very good question, and unfortunately I don't have a simple
    answer.
    The short answer is no, I don't believe that there is any way to
    elevate your user privileges when using File, and I am unaware of any
    method to pass credentials in the UNC path.

    If the security of the data you are transmitting is important I would
    suggest you look to another method ( SFTP? ). Otherwise you will need
    to be accessing a directory/file which the application user already has
    access to (does the program run in a windows domain?), or an
    unauthenticated share.

    Carl.
     
    Carl, Mar 23, 2006
    #5
  6. Chris Uppal Guest

    Alf_Italy wrote:

    > Do you know if there's a way to pass credentials as argument in the
    > uncPath???


    It might be possible if you useJCIFS instead of direct file access:

    http://jcifs.samba.org/

    -- chris
     
    Chris Uppal, Mar 24, 2006
    #6
    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. SD Keane

    Host an app on remote site

    SD Keane, Sep 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    403
    Sam Santiago
    Sep 2, 2004
  2. Matt
    Replies:
    2
    Views:
    401
  3. Pavils Jurjans

    Get detailed error report on remote host

    Pavils Jurjans, Nov 25, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    408
    Scott Allen
    Nov 25, 2004
  4. Orpheus66
    Replies:
    0
    Views:
    4,527
    Orpheus66
    Jul 30, 2003
  5. Jerry Qu
    Replies:
    1
    Views:
    528
    lee atkinson
    Feb 20, 2009
Loading...

Share This Page