Home | History | Annotate | Download | only in scripts
      1 #! /bin/sh
      2 ## Like "rcp" but uses netcat on a high port.
      3 ## do "ncp targetfile" on the RECEIVING machine
      4 ## then do "ncp sourcefile receivinghost" on the SENDING machine
      5 ## if invoked as "nzp" instead, compresses transit data.
      6 
      7 ## pick your own personal favorite port, which will be used on both ends.
      8 ## You should probably change this for your own uses.
      9 MYPORT=23456
     10 
     11 ## if "nc" isn't systemwide or in your PATH, add the right place
     12 # PATH=${HOME}:${PATH} ; export PATH
     13 
     14 test "$3" && echo "too many args" && exit 1
     15 test ! "$1" && echo "no args?" && exit 1
     16 me=`echo $0 | sed 's+.*/++'`
     17 test "$me" = "nzp" && echo '[compressed mode]'
     18 
     19 # if second arg, it's a host to send an [extant] file to.
     20 if test "$2" ; then
     21   test ! -f "$1" && echo "can't find $1" && exit 1
     22   if test "$me" = "nzp" ; then
     23     compress -c < "$1" | nc -v -w 2 $2 $MYPORT && exit 0
     24   else
     25     nc -v -w 2 $2 $MYPORT < "$1" && exit 0
     26   fi
     27   echo "transfer FAILED!"
     28   exit 1
     29 fi
     30 
     31 # fall here for receiver.  Ask before trashing existing files
     32 if test -f "$1" ; then
     33   echo -n "Overwrite $1? "
     34   read aa
     35   test ! "$aa" = "y" && echo "[punted!]" && exit 1
     36 fi
     37 # 30 seconds oughta be pleeeeenty of time, but change if you want.
     38 if test "$me" = "nzp" ; then
     39   nc -v -w 30 -p $MYPORT -l < /dev/null | uncompress -c > "$1" && exit 0
     40 else
     41   nc -v -w 30 -p $MYPORT -l < /dev/null > "$1" && exit 0
     42 fi
     43 echo "transfer FAILED!"
     44 # clean up, since even if the transfer failed, $1 is already trashed
     45 rm -f "$1"
     46 exit 1
     47