18

Given two Linux boxes on a LAN, what's the simplest way to transfer files between them?

11 Answers 11

23

I use scp.

scp source desthost:/path/to/dest/.

to copy from the local machine to the remote machine, or

scp srchost:/path/to/file/file .

to copy from a remote machine to the local machine.

If the username is not the same on the remote machine,

scp user@srchost:/path/to/file/file .
3
  • 3
    I would add you can use -r option with scp to recursively copy an entire directory scp -r source desthost:/path/to/dest/ Aug 11, 2010 at 13:48
  • 1
    @Steve_ Good point. Also -C will compress the files as they are being transferred, which can help over slow links.
    – KeithB
    Aug 11, 2010 at 17:01
  • It's either scp or rsync for me.
    – Josh K
    Aug 11, 2010 at 18:34
6

I usually mount a directory through ssh via FUSE and sshfs.

Mount:

$ sshfs name@server:/path/to/dir /path/to/mount/point

Unmount:

$ fusermount -u /path/to/mount/point
6

nfs could be useful.

The Network File System (NFS) allows a client node to perform transparent file access over the network. By using NFS, a client node operates on files residing on a variety of servers and server architectures, and across a variety of operating systems. File access calls on the client (such as read requests) are converted to NFS protocol requests and sent to the server system over the network.

You might require help from your Unix Admin to setup it first time but its very useful.

1
  • For quick-n-dirty *nix-to-*nix transfers, nothing comes close to NFS. A good admin can crank up both boxes and do transfers in less than 5 minutes, it's near-transparent to the rest of the system, and it's well-known and stable. +1 for something that doesn't require banging out a command line every time to transfer something. Aug 12, 2010 at 1:18
5

I use netcat (if I don't need security)

nc -l -p 1234 < send_file   # 'server'
nc x.y.z.t 1234 > receive_file  # 'client'
1
  • 3
    I especially like this combo: tar -c files and folders/ |pv -cN in|lzop|pv -cN out|nc x.y.z.t 1234
    – jpc
    Mar 22, 2011 at 15:54
3

For one off file transfers, I usually use SFTP or an existing samba share.

For keeping in sync, I suggest you try rsync or unison (for 2-way synchronization)

Edit: scp would be better then sftp, since it would work on all SSH enabled hosts

2

For doing backups I often use rsync. If I want to backup onto a remote machine I'll put a line in /etc/fstab to keep the remote machine mounted by NFS or CFIS (Samba).

192.168.0.101:/ /mnt/backup nfs rsize=8192,wsize=8192,timeo=14,intr 0 0

Then have a line in my crontab using rsync.

rsync -av /home/user/sourcedir/ /mnt/backup/destinationdir > /home/user/backup.log
1

netcat is simple but not all versions close connection reliably.

Here is thread about using socat: socat reliable file transfer over TCP

To sum it up:

Proposed:

Server sending file:

server$ socat -u FILE:test.dat TCP-LISTEN:9876,reuseaddr
client$ socat -u TCP:127.0.0.1:9876 OPEN:out.dat,creat

Server receiving file:

server$ socat -u TCP-LISTEN:9876,reuseaddr OPEN:out.txt,creat && cat out.txt
client$ socat -u FILE:test.txt TCP:127.0.0.1:9876

Proposed enhancements:

  • OPEN:out.txt,creat,trunc will delete all the bytes in out.txt before writing to it. This option mimics what you'd expect from cp, and is probably what you want.
  • OPEN:out.txt,creat,excl will refuse to write out.txt if it already exists. Use this option for extra safety.
  • OPEN:out.txt,creat,append will append data to out.txt.
1

Giver is a simple file sharing desktop application. Other people running Giver on your network are automatically discovered and you can send files to them by simply dragging the files to their photo or icon shown in Giver.

In Ubuntu:

sudo apt-get install giver
0

Also you could use Giver program. Using it you could transfer files over LAN with 2 clicks or by "drag'n'dropping" file to recipient. Recipients (which also have to run giver) are discovered via Zeroconf, so you don't have to know even their IP. Here's video on how Giver works.

2
  • 2
    As somebody who's worked on Giver in the past, I can say it's a neat app, but it's totally unmaintained and has plenty of bugs, especially when it comes to transferring large files. Don't expect much from it.
    – Sandy
    Aug 11, 2010 at 20:20
  • @Sandy yes, I'm aware of bugs. In my case, 1.4G files were transferred successfully. Anyway, using Giver still looks much easier than NFS/rsync/nc/whatever. Aug 15, 2010 at 15:51
0

If you do not have an account (password) on the receiving host you can use woos (web offer one stream):

woos file-or-directory ...

http://fex.belwue.de/fstools/woos.html

0

There are a lot of good answers here, and some mention Giver and how it has trouble with large files. A very similar tool which handles large files seamlessly and gzips the transfer is portal.

(NOTE: I wrote this!)

How to use it

Alice wants to send <folder1> and <file.txt> to Bob, who can be behind the same NAT for direct transfer or anywhere on the internet for relayed transfer. Portal will use direct transfer if it's possible.

Alice initializes the file transfer by executing the following in her shell

$ portal send <folder1> <file.txt>

This outputs a temporary password, which Alice communicates to Bob via some other secure channel.

# the output of the send command, use this password to receive the files 
> 1-supernova-gamma-ray

Bob executes the following command to receive folder1 and file.txt

$ portal receive 1-supernova-gamma-ray

The file transfer will now begin!

Pros

  • e2e encryption
  • fast gzip (de)compression
  • simple protocol aids transfer speed
  • handles folders of any sort and depth
  • direct communication if ports are open or behind same NAT

Cons

  • does not do NAT traversal so transfer goes through a relay if direct communication cannot be established
  • it's a new tool so it is untried in different systems and might have weird bugs
3
  • That's a good point, as it's not at all obvios from my comment. Added!
    – Zino
    Nov 13, 2021 at 16:46
  • Is "Generate password" seriously just a short list of some words? Nov 13, 2021 at 18:37
  • Yes, the password is created from a list of words along with a unique number prefixed, three words along with the prefix create a full password. The password exists only until the connection has been established. Similar tools also work like this. It is a trade-off for being able to communicate the password easily over any channel, such as a voice chat or in-person. The actual communication once established is then fully encrypted.
    – Zino
    Nov 13, 2021 at 18:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .