home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1575 < prev    next >
Internet Message Format  |  1990-12-28  |  3KB

  1. From: jp@hplb.hpl.hp.com (Julian Perry)
  2. Newsgroups: alt.sources
  3. Subject: Recursive ftp from another Unix machine....
  4. Message-ID: <1990Jul12.155536.19483@hplb.hpl.hp.com>
  5. Date: 12 Jul 90 15:55:36 GMT
  6.  
  7. Here's a shell script which connects to a remote machine and pulls in
  8. (in binary mode) all files (recursively downwards) from the named
  9. directories.  It's really handy for example:
  10.     getrftp uunet.uu.net comp.sources.unix/volume14
  11.  
  12. If the ftp fails part way through it will just carry on without bothering
  13. to transfer files it already has.  It will only talk to other Unix ftp
  14. servers.
  15.  
  16. Comments/suggestions/defects?
  17.  
  18. Jules
  19. --
  20. E-MAIL:         jp@hplb.hpl.hp.com || jp@hpl.hp.co.uk
  21. IN-REAL-LIFE:   Julian Perry
  22. ORGANISATION:   Hewlett-Packard Laboratories, Bristol
  23. ADDRESS:        Filton Road, Stoke Gifford, Bristol, England, BS12 6QZ
  24. TELEPHONE:      +44 272 799910 x 24019
  25.  
  26.  
  27. #---------------------------------- cut here ----------------------------------
  28. # This is a shell archive.  Remove anything before this line,
  29. # then unpack it by saving it in a file and typing "sh file".
  30. #
  31. # Wrapped by Julian Perry <jp@hplb.hpl.hp.com> on Thu Jul 12 16:46:32 1990
  32. #
  33. # This archive contains:
  34. #    getrftp    
  35. #
  36. # Existing files will not be overwritten.
  37. # Error checking via wc(1) will be performed.
  38. # Error checking via sum(1) will be performed.
  39.  
  40. LANG=""; export LANG
  41. PATH=/bin:/usr/bin:$PATH; export PATH
  42.  
  43. if sum -r </dev/null >/dev/null 2>&1
  44. then
  45.     sumopt='-r'
  46. else
  47.     sumopt=''
  48. fi
  49.  
  50. if test -f getrftp
  51. then
  52.     echo Ok to overwrite existing file getrftp\?
  53.     read answer
  54.     case "$answer" in
  55.     [yY]*)    echo Proceeding;;
  56.     *)    echo Aborting; exit 1;;
  57.     esac
  58.     rm -f getrftp
  59.     if test -f getrftp
  60.     then
  61.         echo Error: could not remove getrftp, aborting
  62.         exit 1
  63.     fi
  64. fi
  65. echo x - getrftp
  66. cat >getrftp <<'@EOF'
  67. #!/bin/sh
  68. #
  69. # Script to get directories of files (recursively) from a Unix
  70. # ftp server.
  71. #
  72. # Usage:    getrftp <host> <dir1> [<dir2> ...]
  73. #
  74. # File:        getrftp
  75. # Author:    Julian Perry    (jp@hplb.hpl.hp.com)
  76. # Date:        90/07/12
  77. # Revision:    1.0
  78. #
  79.  
  80. USER=ftp
  81. PASSWORD=`hostname`
  82. VERBOSE=-v
  83.  
  84. if [ $# -lt 2 ]
  85. then
  86.   echo "usage: $0 <host> <dir1> [<dir2> ...]"
  87.   exit 1
  88. fi
  89.  
  90. HOST=$1
  91. ROOT=`pwd`
  92. TMPFIL="/tmp/grftp.$$"
  93. trap "rm -f $TMPFIL; trap '' 0; exit" 0 1 2 13 15
  94.  
  95. shift
  96.  
  97. for DIR in $*
  98. do
  99.  
  100.   ftp -v -g -i -n $HOST <<EOF
  101. user $USER $PASSWORD
  102. ls "-pR $DIR" $TMPFIL
  103. quit
  104. EOF
  105.  
  106.   {
  107.   echo "user $USER $PASSWORD"
  108.   echo "binary"
  109.  
  110.   CURDIR=$DIR
  111.   mkdir -p $ROOT/$CURDIR
  112.   cd $ROOT/$CURDIR
  113.  
  114.   echo "lcd $ROOT/$CURDIR"
  115.   echo "cd /"
  116.   echo "cd $CURDIR"
  117.  
  118.   while read line
  119.   do
  120.     if [ ! -z "$line" ]
  121.     then
  122.       case "$line" in
  123.     *:) # Found a directory
  124.         CURDIR=`echo "$line" | sed -e 's/:$//'`
  125.         mkdir -p $ROOT/$CURDIR
  126.         cd $ROOT/$CURDIR
  127.         echo "lcd $ROOT/$CURDIR"
  128.         echo "cd /"
  129.         echo "cd $CURDIR"
  130.         ;;
  131.     */) # Found a directory to be ignored
  132.         ;;
  133.     *)  # Found a file
  134.         if [ ! -f "$line" ]
  135.         then
  136.           echo "get $line"
  137.         fi
  138.       esac
  139.     fi
  140.   done } < $TMPFIL | ftp $VERBOSE -g -i -n $HOST
  141.  
  142. done
  143.  
  144. @EOF
  145. set `sum $sumopt <getrftp`; if test $1 -ne 26669
  146. then
  147.     echo ERROR: getrftp checksum is $1 should be 26669
  148. fi
  149. set `wc -lwc <getrftp`
  150. if test $1$2$3 != 771991213
  151. then
  152.     echo ERROR: wc results of getrftp are $* should be 77 199 1213
  153. fi
  154.  
  155. chmod 755 getrftp
  156.  
  157. exit 0
  158.