Last updated on September 3, 2020 by Dan Nanni
Originally based on BSD RCP protocol, SCP (Secure copy) is a mechanism that allows you to transfer a file between two end points over a secure SSH connection. However, as a simple secure copy protocol, SCP does not understand range-request or partial transfer like HTTP does. As such, popular SCP implementations like the scp
command line tool cannot resume aborted downloads from lost network connections.
If you want to resume an interrupted SCP transfer, you need to rely on other programs which support range requests. One popular such program is rsync
. Similar to scp
, rsync
can also transfer files over SSH.
Suppose you were trying to download a file (bigdata.tgz
) from a remote host remotehost.com
using scp
, but the SCP transfer was stopped in the middle due to a stalled SSH connection. You can use the following rsync
command to easily resume the stopped transfer. Note that the remote server must have rsync
installed as well.
$ cd /path/to/directory/of/partially_downloaded_file $ rsync -P --rsh=ssh [email protected]:bigdata.tgz ./bigdata.tgz
The -P
option is the same as --partial --progress
, allowing rsync
to work with partially downloaded files. The --rsh=ssh
option tells rsync
to use ssh
as a remote shell.
Once the command is invoked, rsync
processes on local and remote hosts compare a local file (./bigdata.tgz
) and a remote file ([email protected]:bigdata.tgz
), determine among themselves what portion of the file is not the same, and transfer the discrepancy to either end. In this case, missing bytes in the partially downloaded local file is downloaded from a remote host.
If the above rsync
session itself gets interrupted, you can resume it as many time as you want by typing the same command. rsync
will automatically restart the transfer where it left off.
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.
Xmodulo © 2021 ‒ About ‒ Write for Us ‒ Feed ‒ Powered by DigitalOcean