home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.dataforce.net
/
2014.05.ftp.dataforce.net.tar
/
ftp.dataforce.net
/
pub
/
solar
/
rescp
< prev
next >
Wrap
Text File
|
1998-04-12
|
2KB
|
78 lines
#!/bin/sh
# Rescp - secure copy with reget. Command line syntax is similar to scp.
# Copyright (c) 1997 by Solar Designer
function usage() {
echo "Usage: $0 [options] [user@]host:file file"
exit 1
}
while getopts "CP:c:i:v" OPT; do
if [ "$OPT" = "?" ]; then
usage
else
if [ "$OPT" = "P" ]; then
OPT="p"
fi
OPTS="$OPTS -$OPT"
if [ "$OPTARG" != "" ]; then
OPTS="$OPTS $OPTARG"
fi
fi
done
if [ $OPTIND -ne $[$#-1] ]; then
usage
fi
shift $[$OPTIND-1]
USER="`echo "$1" | sed -n "s/@.*//p"`"
HOST="`echo "$1" | sed -ne "s/[^@]*@//" -e "s/:.*//p"`"
R_FILE="`echo "$1" | sed -n "s/[^:]*://p"`"
if [ "$USER" = "" ]; then
USER="$LOGNAME"
fi
if [ "$HOST" = "" -o "$R_FILE" = "" ]; then
usage
fi
if [ -d "$2" ]; then
L_FILE="$2/$R_FILE"
else
L_FILE="$2"
fi
if [ ! -f "$L_FILE" -o ! -r "$L_FILE" -o ! -w "$L_FILE" ]; then
echo "Destination file should exist and be both readable and writable"
exit 1
fi
SIZE=$[`wc -c "$L_FILE" | sed -e "s/[ ]*//" -e "s/ .*//"` / 1024]
echo "Restarting at $[$SIZE * 1024]"
ssh -a -x $OPTS -l "$USER" "$HOST" \
"dd if=$R_FILE bs=1k count=$SIZE 2>> /dev/null | md5sum;" \
"dd if=$R_FILE bs=1k skip=$SIZE count=1024k 2>> /dev/null" |
(
if read; then
L_SUM=`dd if="$L_FILE" bs=1k count=$SIZE 2>> /dev/null | \
md5sum | sed -n "s/ .*//p"`
R_SUM=`echo "$REPLY" | sed -n "s/ .*//p"`
if [ "$L_SUM" != "$R_SUM" ]; then
echo "Checksum doesn't match"
exit 1
fi
else
echo "No checksum received"
exit 1
fi
dd of="$L_FILE" bs=1k seek=$SIZE count=1024k 2>> /dev/null
)