How can I resume a large scp file transfer when using port forwarding?

I have a machine a couple of hops away, and I need to set up port forwarding in order to transfer files.

Edit: To be clear, the multiple hops are needed in order to access the remote machine. From my machine, I set up a VPN, where I can access 10.255.x.x - that is the only machine I can connect to via the VPN. Once logged into .x.x, I can then connect to other machines - .y.y being one of those.

From my machine:

ssh -L 4567:localhost:4567 [email protected]

Then from that machine:

ssh -L 4567:localhost:22 [email protected]

I can then

scp -P 4567 me@localhost:/path/to/large/file.gz .

I left this running overnite, only to find that the transfer died at some point.

I've seen a couple of suggestions to use rsync over ssh to resume the transfer, but I'm unclear how to set that up. Is this possible?


With some versions of scp (the version on the source computer seems to be the key), just re-executing the scp command will suffice to resume the transfer. But be careful! If your version doesn't support partial transfers, the partial file will simply be overwritten.

The following rsync switches are handy for resuming a broken transfer if scp doesn't support it:

     --append                append data onto shorter files
     --append-verify         like --append, but with old data in file checksum
 -e, --rsh=COMMAND           specify the remote shell to use
     --progress              show progress during transfer

The command

rsync --append-verify --progress --rsh="ssh -p 4567" me@localhost:/path/to/large/file.gz .

should have the desired effect. Note that the -p switch must be lowercase for ssh.


Use sftp instead of scp

In your case:

sftp -a -P 4567 me@localhost:/path/to/large/file.gz .

From the sftp man page:

-a      Attempt to continue interrupted downloads rather than overwriting existing partial or complete copies of files.  If the remote file contents differ from the partial local copy then the resultant file is likely to be corrupt.

rsync uses ssh by default, you may have to specify the exact ssh command using rsync's -e switch. It also has a --partial which should keep the incomplete file around so it can resume the transfer.