There could be situations when you should copy files or block device to another system via network. There are a few methods to do it.
1. Copy files with ssh:
scp -r /home/user/testdir /etc/init.d/my_init_file firstname.lastname@example.org:
-r means recursively copy directories
First part of command is what exactly we copy (files and dirs), second is where we copy. Two points after ip address means that we want to copy to home dir of user.
2. Copy block device with netcat:
on server where copy:
nc -l -p 5555 | dd of=/dev/sdc
Firstly, execute this command on remote machine that netcat open socket and listen. -l option is LISTEN mode, -p is port. dd command copy block device to /dev/sdc device.
on server from copy:
dd if=/dev/sda bs=1M | nc 192.168.56.2 5555
3. Copy block device with ssh:
dd bs=1M if=/dev/sda | sudo -S ssh email@example.com 'dd bs=1M of=/dev/sdc'
bs option means copy data by 1M.
-S option in sudo means that sudo will ask you passwd from root privileges on remote host.
4. Prevoius example with progress bar:
dd bs=1M if=/dev/sda | pv -s 10g | sudo -S ssh firstname.lastname@example.org 'dd bs=1M of=/dev/sdc
You could use -c flag with ssh for compression data or gzip via pipe. It is useful if you copy data via internet.