home *** CD-ROM | disk | FTP | other *** search
/ ftp.dataforce.net / 2014.05.ftp.dataforce.net.tar / ftp.dataforce.net / pub / solar / rescp < prev    next >
Text File  |  1998-04-12  |  2KB  |  78 lines

  1. #!/bin/sh
  2.  
  3. # Rescp - secure copy with reget. Command line syntax is similar to scp.
  4. # Copyright (c) 1997 by Solar Designer
  5.  
  6. function usage() {
  7.   echo "Usage: $0 [options] [user@]host:file file"
  8.   exit 1
  9. }
  10.  
  11. while getopts "CP:c:i:v" OPT; do
  12.   if [ "$OPT" = "?" ]; then
  13.     usage
  14.   else
  15.     if [ "$OPT" = "P" ]; then
  16.       OPT="p"
  17.     fi
  18.     OPTS="$OPTS -$OPT"
  19.     if [ "$OPTARG" != "" ]; then
  20.       OPTS="$OPTS $OPTARG"
  21.     fi
  22.   fi
  23. done
  24.  
  25. if [ $OPTIND -ne $[$#-1] ]; then
  26.   usage
  27. fi
  28.  
  29. shift $[$OPTIND-1]
  30.  
  31. USER="`echo "$1" | sed -n "s/@.*//p"`"
  32. HOST="`echo "$1" | sed -ne "s/[^@]*@//" -e "s/:.*//p"`"
  33. R_FILE="`echo "$1" | sed -n "s/[^:]*://p"`"
  34.  
  35. if [ "$USER" = "" ]; then
  36.   USER="$LOGNAME"
  37. fi
  38.  
  39. if [ "$HOST" = "" -o "$R_FILE" = "" ]; then
  40.   usage
  41. fi
  42.  
  43. if [ -d "$2" ]; then
  44.   L_FILE="$2/$R_FILE"
  45. else
  46.   L_FILE="$2"
  47. fi
  48.  
  49. if [ ! -f "$L_FILE" -o ! -r "$L_FILE" -o ! -w "$L_FILE" ]; then
  50.   echo "Destination file should exist and be both readable and writable"
  51.   exit 1
  52. fi
  53.  
  54. SIZE=$[`wc -c "$L_FILE" | sed -e "s/[ ]*//" -e "s/ .*//"` / 1024]
  55.  
  56. echo "Restarting at $[$SIZE * 1024]"
  57.  
  58. ssh -a -x $OPTS -l "$USER" "$HOST" \
  59.   "dd if=$R_FILE bs=1k count=$SIZE 2>> /dev/null | md5sum;" \
  60.   "dd if=$R_FILE bs=1k skip=$SIZE count=1024k 2>> /dev/null" |
  61. (
  62.   if read; then
  63.     L_SUM=`dd if="$L_FILE" bs=1k count=$SIZE 2>> /dev/null | \
  64.       md5sum | sed -n "s/ .*//p"`
  65.     R_SUM=`echo "$REPLY" | sed -n "s/ .*//p"`
  66.  
  67.     if [ "$L_SUM" != "$R_SUM" ]; then
  68.       echo "Checksum doesn't match"
  69.       exit 1
  70.     fi
  71.   else
  72.     echo "No checksum received"
  73.     exit 1
  74.   fi
  75.  
  76.   dd of="$L_FILE" bs=1k seek=$SIZE count=1024k 2>> /dev/null
  77. )
  78.