#!/bin/bash # autoftp -- script for FTP'ing a list of files # Copyright 1998 by Richard L. Hawes under the GNU GPL v. 2 # email: rhawes@dmapub.dma.org web: http://www.dma.org/~rhawes SYNOPSIS="autoftp -{h|g|l|n|p|r|s} [-{C|E|T} arg] FTP_ADDR REM_PATH < FILE_LIST" VERSION='$Id: autoftp,v 0.93 1998/10/30 04:24:58 hr Exp $' # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA set -h # init vars FTPCmd_Ptr="pftp -iv" FTP_Commands="" MD_Func_Ptr="" ArchCmd_Ptr=":" function Do_FTP { # get site ftp files local FTCmd="$1" { # Connects to the ftp site at FTP_ADDRESS # through auto-login, # changes the remote directory to Rem_Path, echo "open $FTP_Addr cd $Rem_Path" echo "binary" echo "$FTP_Commands" while read File do if test "$File"; then $MD_Func_Ptr # gets the files listed in the standard input, echo "$FTCmd $File" $ArchCmd_Ptr $File fi done } | $FTPCmd_Ptr || exit } function MkDir_Func { # get site ftp files Directory=`dirname $File` if test ! -d $Directory; then mkdir -p $Directory fi } function DL_FTP { # get site ftp files MD_Func_Ptr="MkDir_Func" Do_FTP $@ } function Size { # get site ftp files Do_FTP $@ | \ awk ' BEGIN{sum=0} /^[0-9]+ [0-9].*/ {sum += $2} { print } END{print sum}' } function Error { # usage error message echo "$1 usage: $SYNOPSIS use -h for more information." >&2 exit 2 } function Version { # version echo "autoftp version: `echo $VERSION | cut -f3 -d' '` Copyright (C) 1998 by Richard L. Hawes autoftp comes with NO WARRANTY, to the extent permitted by law. You may redistribute copies of autoftp under the terms of the GNU General Public License version 2. For more information about these matters, see the file named COPYING." exit } function Help_FTP { # help cat <