Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scp stalled while copying large files

Tags:

bash

shell

scp

According to the needs of the experiment, I set the MTU to 8000. After doing this, when I use scp to copy large files, it stalled with 0.00%. I tried scp -l or scp -C and turning tcp_sack on/off, but it still didn't work. And I can't change the MTU size for experiment result comparison. Is there any other way to help?

like image 750
flyhighzy Avatar asked Dec 17 '13 02:12

flyhighzy


People also ask

Why is the scp getting stalled?

The reason for scp to stall, is because scp greedily grabs as much bandwith of the network as possible when it transfers files, any delay caused by the network switch of the firewall can easily make the TCP connection stalled.

How do you resume a stalled scp?

Yes, if both ends support sftp - after scp remoteuser@remotehost:/absolute/filename . fails you can resume by doing sftp remoteuser@remotehost and then reget /absolute/filename to resume the download.

Is there a size limit for scp?

Short description. The maximum size for SCPs policy documents is 5,120 bytes.

What is difference between scp and rsync?

Copying files and directories with SCP or Rsync Secure Copy (SCP) uses SSH to copy only the files or directories that you select. On first use, Rsync copies all files and directories and then it copies only the files and directories that you have changed. It does not copy all the files and directories again.


1 Answers

An attempt at a comprehensive solution, as there could be several problems and limitations depending on your situation.

rsync

My preferred option: using rsync doesn't give this problem and is a bit more versatile in my opinion, e.g. it keeps track of which files are already there, so if the connection ever does break it can pick up from where it left off - try the --partial flag too - among other things.

Instead of

scp local/path/some_file [email protected]:"/some/path/" 

you can just do

rsync -avz --progress local/path/some_file [email protected]:"/some/path/" 

I've tested this on several occasions when scp would give me the same problem it gave you - and now I just use rsync by default.

Limit speed

Not a solution for OP as the MTU is fixed in this situation (and probably not the issue here), but if the culprit is a slow/unreliable connection between the two drives, setting a speed limit reduces the delays which make the TCP connection stall - at the expense of a slower transfer of course. This is because scp grabs all the bandwidth it can get unless you specify the maximum data rate in kilobits, like so:

scp -l 8192 local/path/some_file [email protected]:"/some/path/" 

This doesn't always work though.

Compression option

scp's -C option can speed up the transfer, reducing the probability that the transfer stalls.

Disabling TCP SACK

As mentioned by the OP, and here.

sudo sysctl -w net.ipv4.tcp_sack=0 

(or similar)

LAN card MTU

Again an MTU fix, not necessarily of the transfer specifically though:

ifconfig eth0 mtu 1492 

or on newer (Linux) systems:

ip link set dev eth0 mtu 1492 

Other

If all else fails, this lists another handful of potential solutions not included here.

The more exotic hpn bug may be at fault too.

like image 73
BrechtDeMan Avatar answered Sep 21 '22 23:09

BrechtDeMan