#!/bin/ksh
# Filename: sig_ftp
# Sends files via ftp, syntax:
# sig_ftp SourcePath DestPath DestHost User Password [RenameName]
trap "" HUP
SourcePath=$1
SourceDir=${SourcePath%/*}
SourceFile=${SourcePath##*/}
DestPath=$2
DestDir=${DestPath%/*}
DestFile=${DestPath##*/}
DestHost=$3
# For security, you can always hard code in the username and/or 
# password here.
User=$4
Password=$5
Rename=$6

# Error checking: Make sure each string has a value.

if [ "${SourceDir}"  = "" ]; then exit 1; fi
if [ "${SourceFile}" = "" ]; then exit 1; fi
if [ "${DestDir}"    = "" ]; then exit 1; fi
if [ "${DestFile}"   = "" ]; then exit 1; fi
if [ "${DestHost}"   = "" ]; then exit 1; fi
if [ "${User}"       = "" ]; then exit 1; fi
if [ "${Password}"   = "" ]; then exit 1; fi

cd $SourceDir

if [ "${Rename}" = "" ]; then

  # For debugging, consider adding the -v option, and running
  # manually from a shell.
  ftp -n -g << END_OF_FTP1
    open $DestHost
    user $User $Password
    binary
    cd $DestDir
    put $SourceFile $DestFile
    quit
END_OF_FTP1
  exit $?

else
    
  # For debugging, consider adding the -v option, and running
  # manually from a shell.
  ftp -n -g << END_OF_FTP2
    open $DestHost
    user $User $Password
    binary
    cd $DestDir
    put $SourceFile $DestFile
    rename $DestFile $Rename
    quit
END_OF_FTP2
  exit $?

fi
