15e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project#! /bin/sh 25e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project## Like "rcp" but uses netcat on a high port. 35e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project## do "ncp targetfile" on the RECEIVING machine 45e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project## then do "ncp sourcefile receivinghost" on the SENDING machine 55e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project## if invoked as "nzp" instead, compresses transit data. 65e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project 75e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project## pick your own personal favorite port, which will be used on both ends. 85e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project## You should probably change this for your own uses. 95e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source ProjectMYPORT=23456 105e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project 115e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project## if "nc" isn't systemwide or in your PATH, add the right place 125e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project# PATH=${HOME}:${PATH} ; export PATH 135e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project 145e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Projecttest "$3" && echo "too many args" && exit 1 155e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Projecttest ! "$1" && echo "no args?" && exit 1 165e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Projectme=`echo $0 | sed 's+.*/++'` 175e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Projecttest "$me" = "nzp" && echo '[compressed mode]' 185e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project 195e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project# if second arg, it's a host to send an [extant] file to. 205e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Projectif test "$2" ; then 215e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project test ! -f "$1" && echo "can't find $1" && exit 1 225e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project if test "$me" = "nzp" ; then 235e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project compress -c < "$1" | nc -v -w 2 $2 $MYPORT && exit 0 245e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project else 255e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project nc -v -w 2 $2 $MYPORT < "$1" && exit 0 265e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project fi 275e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project echo "transfer FAILED!" 285e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project exit 1 295e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Projectfi 305e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project 315e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project# fall here for receiver. Ask before trashing existing files 325e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Projectif test -f "$1" ; then 335e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project echo -n "Overwrite $1? " 345e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project read aa 355e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project test ! "$aa" = "y" && echo "[punted!]" && exit 1 365e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Projectfi 375e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project# 30 seconds oughta be pleeeeenty of time, but change if you want. 385e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Projectif test "$me" = "nzp" ; then 395e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project nc -v -w 30 -p $MYPORT -l < /dev/null | uncompress -c > "$1" && exit 0 405e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Projectelse 415e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project nc -v -w 30 -p $MYPORT -l < /dev/null > "$1" && exit 0 425e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Projectfi 435e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Projectecho "transfer FAILED!" 445e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Project# clean up, since even if the transfer failed, $1 is already trashed 455e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Projectrm -f "$1" 465e0936b99e2d50769c5432b47c4d07c3dcdd37c6The Android Open Source Projectexit 1 47