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

    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("\\\\\\temp\\myFile.txt"));

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

    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 .

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Rep Power


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

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


    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 is offline Senior Member
    Join Date
    Dec 2009
    Belgrade, Serbia
    Rep Power


    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/
    -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 and add it's content to file:

    - (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@
    or ssh root@


    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.



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


    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:
    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, 11:31 AM
  2. Need Help on Remote Host Screen Capture
    By krishnaraoveera1294 in forum AWT / Swing
    Replies: 4
    Last Post: 03-13-2009, 11:56 PM
  3. Replies: 0
    Last Post: 10-31-2008, 08:07 PM
  4. Looking Up the Address of a Host
    By Java Tip in forum
    Replies: 0
    Last Post: 04-07-2008, 09:11 PM
  5. Getting host name/address
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-19-2007, 05: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