#!/bin/csh -f # A shell script to copy a directory tree to another machine using ftp. # The name of the local directory, the (optionally new) name of the remote directory, # the network name of the remote machine, and the password on the remote # machine are queried interactively. # The script demands that the following ftp commands are supported: # mkdir, put, user, cd, quit # (R. J. Mathar, FZR/FWIT, 23.06.1993) if ( "$1_" =~ '-u_' || "$1_" !~ '-v_' && "$1_" !~ '-d_' && "$1_" !~ '_') then echo usage: echo $0 '[-v] (verbose mode with more output)' echo $0 '[-d] (debug mode: creates a standard input file ' echo ' for ftp, but does not execute ftp)' exit 1 endif # Prevent other people from reading the ftp-script-file: # it contains the remote login password umask 077 echo 'name of remote machine ?' set remote=$< # create valid login on remote machine without use of $HOME/.netrc # Prevent spectators from reading the password while typing in. echo login on remote machine '[' ${user} '] ? ' set ruser=$< if( ${ruser}_ == '_') set ruser=${user} echo 'password on remote machine ?' stty -echo set passwd=$< stty echo echo current local directory is `pwd`: ls -CFaq echo name of directory on local machine echo '(full pathname or $HOME or . or .. or local directory name) ?' set ldir=$< switch ($ldir) case '$HOME': case '$home': set ldir=$HOME breaksw case '.': set ldir=`pwd` breaksw case '..': set ldir=`(cd ..; pwd;)` breaksw case '/*': breaksw default : set ldir=`pwd`/$ldir endsw if ("$1_" == "-v_") echo Local directory chosen is $ldir . echo 'name of directory on remote machine (different or same) ?' set dir=$< cd ldir >/dev/null # Create temporary file with the standard input of ftp session. # First create valid login echo user ${ruser} ${passwd} > $0.$$ # List all subdirectories and the directory # itself, and place 'mkdir' in front of these names. # Mkdir will create all levels of subdirectories on the remote machine. # The stream editro substitutse the leading full stop of the output of # find with the full pathname of the local directory. # (Some safety factor, as it is not sure from which working directory the # ftp will be started later on.) find . -type d -print | sed -e "s/\./$dir/" | awk '{print "mkdir " $o}' >> $0.$$ # Switch to new directory on remote machine, so we may use # relative path names on the remote machine for the put commands. echo cd ${dir} >> $0.$$ # List all files and prepend each file with 'put'. # Alternatively we might use mput-commands in the form # mput ${ldir/* # mput ${ldir/*/* # but it is not clear, how deeply the subdirectories are nested, and this form # would also try to put directories, which is not allowed from within ftp. # Put only plaine files (no directories, no special files). # Remove the leading full dot and slash left over from the find command. find . -type f ! -name $0.$$ -print | sed -e 's+^\./++' | awk '{print "put " $0 }' >> $0.$$ # Command to leave ftp. echo quit >> $0.$$ if( "$1_" !~ '-d_') then # Start ftp without trying automatic login. if( "$1_" == '-v_') then ftp -n -i ${remote} < $0.$$ else ftp -n -i ${remote} < $0.$$ > /dev/null endif # Remove the temporary help file rm $0.$$ else echo Created standard input file for ftp is $ldir/$0.$$ . echo The ftp transfer may be started with echo " ftp -n -i ${remote} < $ldir/$0.$$ ." endif