Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
resume scp HOWTO
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
pyxel
n00b
n00b


Joined: 04 Nov 2005
Posts: 44
Location: Bratislava/brussels

PostPosted: Wed Feb 15, 2006 5:08 pm    Post subject: resume scp HOWTO Reply with quote

Hello, I find a little script for scp resume:

Code:
#!/bin/sh

. /home/pyxel/scripts/functions.sh

usage()
{
  echo
  echo "Usage: `basename $0` -u(pload)   \$localfile  \$remotefile"
  echo "       `basename $0` -d(ownload) \$remotefile \$localfile"
  echo
  echo "  \$remotefile should be in the scp format, i.e.: user@host:filename"
  echo "      and can be user@host: for uploading"
  echo
  exit 1
}

[ -z "$1" -o -z "$2" -o -z "$3" ] && usage

option=$1
case $option in
  -u*|-U*)
    localfile=$2
    remote=$3

    remove_pattern "${remote}" ":.*$" userhost
    remove_pattern "${remote}" "^.*:" remotefile

    if [ ! -f "$localfile" ]; then
      echo "File not found: $localfile"
      usage
    fi
    if [ x"$userhost" = x"$remote" ]; then usage; fi
    if [ x"$remotefile" = x"$remote" -o -z "$remotefile" ]; then remotefile=`basename "$localfile"`; fi
   

    echo "Getting size of remote file:"
    localsize=`ls -l "${localfile}" | awk '{ print $5 }'`
    remotesize=`ssh "$userhost" "[ -f \"${remotefile}\" ] && ls -l \"${remotefile}\"" | awk '{ print $5 }' `

    if [ -z "$remotesize" ]; then remotesize=0; fi
   
    if [ $localsize -eq $remotesize ]; then
      echo "Local size equals remote size, nothing to transfer."
      exit 0;
    fi
   
    echo "Resuming upload of '$localfile' at byte $remotesize..."

    dd bs=1 skip=$remotesize "if=${localfile}" | \
      ssh "$userhost" "cat >> \"$remotefile\""

    echo "done."
    ;;
  -d*|-D*)
    localfile=$3
    remote=$2

    remove_pattern "${remote}" ":.*$" userhost
    remove_pattern "${remote}" "^.*:" remotefile

    debug_var localfile remote userhost remotefile

    if [ x"$localfile" = x"." ]; then localfile=`basename "$remotefile"`; fi
    if [ ! -f "$localfile" ]; then
      localsize=0;
    else
      localsize=`ls -l "${localfile}" | awk '{ print $5 }'`
    fi
    if [ x"$remotefile" = x"$remote" ]; then usage; fi

   
    if [ -z "$localsize" ]; then localsize=0; fi

    echo "Resuming download of '$localfile' at byte $localsize..."
    ssh "$userhost" "dd bs=1 skip=$localsize \"if=${remotefile}\"" >> $localfile

    ;;
  *)
    usage
    ;;
esac


enjoy.
Back to top
View user's profile Send private message
viperlin
Veteran
Veteran


Joined: 15 Apr 2003
Posts: 1319
Location: UK

PostPosted: Fri Feb 17, 2006 5:41 am    Post subject: Reply with quote

or use rsync..
Back to top
View user's profile Send private message
beandog
Bodhisattva
Bodhisattva


Joined: 04 May 2003
Posts: 2072
Location: /usa/utah

PostPosted: Fri Feb 17, 2006 6:36 am    Post subject: Reply with quote

I think yafc can do resume too. Can't remember.
_________________
If it ain't broke, tweak it. dvds | blurays | blog | wiki
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum