Results 1 to 5 of 5
  1. #1
    isotoper is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default copy file from local host to remote host

    Hi ,
    I need to copy File to a remote linux computer on the same LAN.
    I used this code :

    InputStream in = new FileInputStream(new File("C:\\temp\\myFile.txt"));
    OutputStream out = new FileOutputStream(new File("\\\\9.148.86.166\\temp\\myFile.txt"));

    // Transfer bytes from in to out
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
    }
    in.close();
    out.close();


    When I copy the file to remote windows it works great, but when i try to copy to linux, It doesn't work.

    Please help .
    Thanks.

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Linux has high amount of security, so make sure the directory where you are saving the file has got rw permission.
    Swastik

  3. #3
    mac's Avatar
    mac
    mac is offline Member
    Join Date
    Dec 2009
    Location
    St. Petersburg, Russia
    Posts
    81
    Rep Power
    0

    Default

    Is there another way to do it? Perhaps a different way without having to rewrite the content of a file?

    I too need to try to do something similar to this. Instead of copying data from a local box, I need to copy file(s) from a variety of destination hosts to my local server.

    Would someone suggest how to best accomplish this?

  4. #4
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    364
    Rep Power
    5

    Default

    If you want to send file from one Linux machine to other Linux
    using SSH and and SCP u can do this:

    //create key pair par kljuceva
    ssh-keygen -t rsa (3X hit Enter key)

    -Generating public/private rsa key pair.
    -Enter file in which to save the key (/home/user1/.ssh/id_rsa):
    -Created directory '/home/user1/.ssh'.
    -Enter passphrase (empty for no passphrase):
    -Enter same passphrase again:
    -Your identification has been saved in /home/user1/.ssh/id_rsa.
    -Your public key has been saved in /home/user1/.ssh/id_rsa.pub.
    -The key fingerprint is:
    -31:df:a5:73:4a:2f:a6:6c:1c:32:a2:f2:b3:c5:a7:1f user1@computer1


    now on target Linux send id_rsa.pub and add it's content to file:
    $HOME/.ssh/authorized_keys

    - (target machine) set permissions for za authorized_keys and .ssh folder
    chmod 700 /root/.ssh
    chmod 600 /root/.ssh/authorized_keys

    - now you should be able to perform SSH or SCP without password

    scp filename root@10.0.1.17:/root/some_folder
    or ssh root@10.0.1.17

    ---

    Now you can use SCP command from Java client program directly
    to perform file copy to target Linux mashine, which has public key of sender,
    and all permissions set

    Use :

    Java Code:
    Process p = Runtime.getRuntime().exec(command);
    where command is proper SCP command

    ---

    This approach solves Linux-copy file -Linux permission problems very easy.

    ---

    If you copy from Windows to Linux
    you can use "pscp.exe" and "puttygen.exe" for key pairs creation.

    ---

    regards

  5. #5
    raqman is offline Member
    Join Date
    Sep 2009
    Posts
    37
    Rep Power
    0

    Default

    Use the ftp command to copy a file from a local host to a remote host.

    To copy a file from a local host to a remote host using the ftp command, you must first log in to the remote system either directly or indirectly. See Logging in to a remote host directly or Logging in to a remote host indirectly for instructions.

    Note: The ftp command uses the ASCII default transfer type to copy files.
    To copy a file from a local host to a remote host:

    1. If you want to place the file in a directory other than the $HOME directory, use the cd subcommand to move to the desired directory.
    2. To copy your local file using binary image, type:
    binary
    3. To copy a file to the remote host, type:
    put FileName
    4. To end the session, press the Ctrl-D key sequence, or type quit.
    RAQ Report: free Java reporting tool.

Similar Threads

  1. Host Blacklisted
    By neeti in forum Networking
    Replies: 6
    Last Post: 10-27-2009, 10:31 AM
  2. Need Help on Remote Host Screen Capture
    By krishnaraoveera1294 in forum AWT / Swing
    Replies: 4
    Last Post: 03-13-2009, 10:56 PM
  3. Replies: 0
    Last Post: 10-31-2008, 07:07 PM
  4. Looking Up the Address of a Host
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-07-2008, 08:11 PM
  5. Getting host name/address
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-19-2007, 04:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •