#!/bin/sh ######################################################################### # # FILE : doFtp # DATE : 17.9.2001 # AUTHOR : Patrick Meier / patrick.meier@gmx.net # DESCRIPTION : execute a ftp-command on a specific host # # Copyrigth (C) 2001 by Patrick Meier, Switzerland # ######################################################################### PN=`basename "$0"` STARTSTRING="==>" LINE="-------------------------------------------------------------------------------" FTP="/usr/bin/ftp -n" ######################################################################### # Usage ######################################################################### Usage() { echo "$PN - execute a ftp-command on a specific host (like get, put dir ...)" echo "usage: $PN [ -user username ] [ -password password ] [-host hostname ] [-localPath local-path ] [-remotePath remote-path ] [-command ftp-command ] file1 file2..." exit 1 } ######################################################################### # ParameterFailed ######################################################################### ParameterFailed() { echo "${STARTSTRING}Parameter faild: $1 ..."; echo "" Usage } ######################################################################## # main ######################################################################### currentCommand="dir" currentLocalPath="" currentRemotePath="." while [ $# -gt 0 ] do case "$1" in -help) Usage; exit 1;; -command) if [ $# -gt 1 ] ; then currentCommand="$2"; shift; else ParameterFailed "$1 archive-name.tar"; fi;; -user) if [ $# -gt 1 ] ; then currentUser="$2"; shift; else ParameterFailed "$1 archive-name.tar"; fi;; -password) if [ $# -gt 1 ] ; then currentPassword="$2"; shift; else ParameterFailed "$1 archive-name.tar"; fi;; -host) if [ $# -gt 1 ] ; then currentHostname="$2"; shift; else ParameterFailed "$1 archive-name.tar"; fi;; -localPath) if [ $# -gt 1 ] ; then currentLocalPath="$2"; shift; else ParameterFailed "$1 archive-name.tar"; fi;; -remotePath) if [ $# -gt 1 ] ; then currentRemotePath="$2"; shift; else ParameterFailed "$1 archive-name.tar"; fi;; -mail) if [ $# -gt 1 ] ; then currentMailUser="$2"; shift; else ParameterFailed "$1 archive-name.tar"; fi;; -*) Usage; exit 1;; *) break;; esac shift done if [ -z "$currentHostname" ] then Usage exit fi echo $LINE echo "${STARTSTRING}programm: $PN / `date`" echo $LINE echo "${STARTSTRING}$currentCommand on $currentHostname/$currentRemotePath ($currentLocalPath/$@)" if [ -z "$currentUser" ] then currentUser="anonymous" fi if [ -z "$currentPassword" ] then currentPassword="info@`hostname`" fi ############################################## # ATTENTION: I use here a 'here document'! Please do nothing change below. ############################################## if [ -n "$currentLocalPath" ] then cd $currentLocalPath fi command="$FTP << EOF open $currentHostname user $currentUser $currentPassword bin cd $currentRemotePath " if [ $# -lt 1 ] then command="$command $currentCommand " else for i in $@ do command="$command $currentCommand $i " done fi command="$command close" result="`eval \"$command\"`" if [ -n "$result" ] then if [ -n "$currentMailUser" ] then echo "${STARTSTRING}send mail to $currentMailUser because there are errors" echo "$result" | mail -s "ftp error: `hostname`" $currentMailUser else echo "$result" fi fi echo $LINE ######################################################################### # EOF #########################################################################