recursive ftp

Darrell McCauley mccauley at ecn.purdue.edu
Wed Dec 9 12:53:11 EST 1992


Duc Nygen (duc at comsearch.com) writes on 8 Dec 92:
>Dear Grassers:
>  I would like to get all the updates to grass4.0, however it appears that
>these are in many directories, and they are quite clumsy to retrieve via ftp
>and/or ftpmail.  Could someone on the moon cpio into a .Z file ?
>  Many thanks
>  cheers
>  duc at comsearch.com
>


save as getrftp, chmod +x

#!/bin/sh
#
# Script to get directories of files (recursively) from a Unix
# ftp server.
#
# Usage:	getrftp <host> <dir1> [<dir2> ...]
#
# File:		getrftp
# Author:	Julian Perry	(jp at hplb.hpl.hp.com)
# Date:		90/07/12
# Revision:	1.0
#

USER=anonymous
PASSWORD=`whoami`@`hostname`
VERBOSE=-v

if [ $# -lt 2 ]
then
  echo "usage: $0 <host> <dir1> [<dir2> ...]"
  exit 1
fi

HOST=$1
ROOT=`pwd`
TMPFIL="/tmp/grftp.$$"
trap "rm -f $TMPFIL; trap '' 0; exit" 0 1 2 13 15

shift

for DIR in $*
do

  ftp -v -g -i -n $HOST <<EOF
user $USER $PASSWORD
ls "-pR $DIR" $TMPFIL
quit
EOF

  {
  echo "user $USER $PASSWORD"
  echo "binary"

  CURDIR=$DIR
  mkdir -p $ROOT/$CURDIR
  cd $ROOT/$CURDIR

  echo "lcd $ROOT/$CURDIR"
  echo "cd /"
  echo "cd $CURDIR"

  while read line
  do
    if [ ! -z "$line" ]
    then
      case "$line" in
	*:) # Found a directory
	    CURDIR=`echo "$line" | sed -e 's/:$//'`
	    mkdir -p $ROOT/$CURDIR
	    cd $ROOT/$CURDIR
	    echo "lcd $ROOT/$CURDIR"
	    echo "cd /"
	    echo "cd $CURDIR"
	    ;;
	*/) # Found a directory to be ignored
	    ;;
	*)  # Found a file
	    if [ ! -f "$line" ]
	    then
	      echo "get $line"
	    fi
      esac
    fi
  done } < $TMPFIL | ftp $VERBOSE -g -i -n $HOST

done

--



More information about the grass-user mailing list