I am trying to have an infinite scp between two hosts but of course there is no such file large enough for this.

I tried

scp -l 512 /dev/null

But scp says /dev/zero not a regular file.

I need a consistent traffic between two hosts so I can try something on my router/firewall and I really need it to run for a long time.

Any suggestions? It does not have to be scp but I need to be able to specify the speed.



The scp tool expects to copy a file. You can use ssh to transport an unending stream of bytes, and you can rate-limit with something like pv. The pertinent section of the man page for pv writes,

-L RATE, --rate-limit RATE Limit the transfer to a maximum of RATE bytes per second. A suffix of K, M, G, or T can be added to denote Kilobytes (*1024), Megabytes, and so on.

A suitable solution would be something like this, which rate-limits at approximately 10Mb/s (remember that 1MB/s is approximately 10Mb/s, after accounting for padding, network headers, etc.):

pv --rate-limit 1M </dev/zero | ssh user@example.net 'cat >/dev/null'

If you want bidirectional traffic flow, remove the quotes from the 'cat >/dev/null'.

| improve this answer | |
  • +1. you can also do this with scp itself if you use a modernish shell (e.g. bash, ksh, zsh. not ash or dash) that supports process substitution. scp <(pv ...) user@example.net:/dev/null – cas Jan 24 '18 at 2:13
  • I tried this on CentOS 7 scp still compliants about not a regular file. – Ask and Learn Jan 24 '18 at 3:11
  • so it does...I should have tested that before commenting. maybe there is some valid reason for scp to care whether a file is a regular file or not. or maybe it's just some over-zealous special-case handling. dunno. – cas Jan 24 '18 at 6:17
  • @cas it introduces ambiguity, so it's blocked. Consider scp /dev/sdc3 remote:/dev/sdc3 where the destination does not exist. Should this copy the device node? What about its contents? Since sdc3 is missing on the target should we copy the contents to a file on the destination? – roaima Jan 24 '18 at 8:04
  • 1
    rsync is different to ssh or scp. BTW, for live-migrating VMs, I zfs send the VM's ZVOL to my secondary VM host :), and that's usually very quick because it's only a small update since the most recent snapshot send. The DRBD idea in the strugglers.net article is nicely implemented in google's ganeti. I've got ganeti working with ZFS at home, but I don't really need ganeti here. libvirt plus my own scripts suffice. $workplaces that have paid me to do VM stuff tend to go for vmware, xen, openstack, or containers with docker. I quite like the latter 3. – cas Jan 24 '18 at 10:14

from commandlinefu.com:
dd if=/dev/zero bs=4096 count=1048576 | ssh user@host.tld 'cat > /dev/null'

As a helpful user posted, this will stop at 4GiB, which is not infinite. Therefore:

</dev/zero ssh user@host.tld 'cat > /dev/null'

| improve this answer | |
  • 1
    4GB is not infinite. Why make this complicated? </dev/zero ssh user@host.tld 'cat > /dev/null' – Gilles 'SO- stop being evil' Jan 23 '18 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.