Tip: scp Resume

April 5th, 2006

I often use the UNIX command line tool scp (secure copy) to copy a file to a remote server. However, scp has one major drawback: It doesn’t support resuming a transfer. So whenever I’m transferring a file and something comes up which interrupts my transfer–which is bound to happen–I’m cursing away at scp. The solution? Use rsync. It is overkill for most things I do, but when a transfer is interrupted, it is handy. Now, on to the doing.

I want to transfer the file “myFile” to the server “remoteMachine”, which I do with scp:
scp myFile remoteMachine:dirToPutIn/
(You should know this already if you’re reading this in the first place.)

(Muzak while the transfer is in progress; a loud wail and the sound of hair being torn out by its roots as the transfer comes to a grinding halt.)

Time to resume the file with rsync, which I do thusly:
rsync --partial --progress myFile remoteMachine:dirToPutIn/
The “–partial” argument is what does the trick. I added “–progress” because I like to see how the transfer is going; rsync understandably doesn’t show this by default as it is mostly used for purposes which don’t require live progress reporting (e.g. scheduled backups).

Because I know I’ll have this problem again at some point, I have created an alias in my shell’s (zsh) configuration file (~/.zshrc):
alias scpresume="rsync --partial --progress"
I know that rsync and scp are not necessarily related, but the name “scpresume” reflects the purpose of the task I wish to do. And getting it done is what matters the most after all.

Update:
Jan pointed out in a comment that rsync communication is not secure by default, and that you should use tunneling to achieve secure communication. Andi provides the solution which is quite simple: Use --rsh=ssh (use ssh as the remote shell). Thus, our alias from before would look like this: alias scpresume="rsync --partial --progress --rsh=ssh"

Entry Filed under: UNIX, Tips & Tricks

6 Comments

  • 1. Jesper  |  April 6th, 2006 at 10:14 pm

    Nifty tip, will come in handy with those large transfers. I didn’t actually know about this one, and have used homegrown scripts for doing the trick.

    One correction: ~/.zshrc, you forgot the dot ;-)

  • 2. Joen  |  April 8th, 2006 at 9:32 am

    Fixed :)

  • 3. Jan  |  April 23rd, 2006 at 12:19 pm

    Keep in mind that you rsync-method lacks any form of encryption. For non-local transfers you would be better off tunneling rsync through ssh.

  • 4. Joen  |  April 23rd, 2006 at 3:53 pm

    Jan: Thanks for pointing that out :)

  • 5. Andi  |  May 7th, 2006 at 7:02 pm

    tunneling is simply done by:

    rsync –partial –progress –rsh=ssh :

    taken from the rsync man page. So an shell alias would look like:

    alias scpresume=rsync –partial –progress –rsh=ssh

  • 6. Joen  |  May 7th, 2006 at 9:22 pm

    Thanks, Andi. Post updated.


Calendar

August 2010
M T W T F S S
« Apr    
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Most Recent Posts