#!/bin/bash
# Script to invoke ncftpput.  This script is intended for use
# by Service Agent and will invoke the ncftpput command.
#
# Format: ncftpput -c remote-host "remote-path-name" <stdin
#
# Usage:
#     saFtpOffLoad <parms>
#
#     <parms>
#         $1 file to copy
#         $2 userid
#         $3 password
#         $4 port
#         $5 passive mode (-F=passive, -E=regular port)
#         $6 debug file
#         $7 server
#         $8 serverpathname
#         $9 path name to the ncftp filewall control file that contains the 
#            info on the external firewall. Only used for test button.
#
#
# Exit status = 0 if no errors occur; non-zero otherwise.
#
#
# Module History:
# 00 07/14/2004  M. Gregor     Initial release
# 00 08/25/2004  M. Gregor     Updates to support passive mode and debug file
# 00 10/08/2004  M. Gregor     Pass back ncftpput rc
# 00 02/15/2008  S. Lyons      646662  test botton on ftp screen does not use the values from the gui.

actzTrace "ESA    T: -> saFtpOffLoad $*"

if (($# < 8)); then
   actzTrace 'ESA    F: Missing required argument(s).'
   exit 100
fi

if [ "$9" != "" ]; then
  # This is the test button case, $9 is the directory were the firewall control file is found. 
  # /opt/ccfw/data/p/sa/FtpTestTempDirNameyyMMddHHmmss/firewall 
  export NCFTPDIR="$9"
  actzTrace "ESA    F: exporting NCFTPDIR = $9 "
fi

(cat $1 | /usr/bin/ncftpput -u $2 -p $3 -P $4 $5 -d $6 -c $7 $8)
ftpRC=$?

actzTrace 'ESA    T: <- saFtpOffLoad'

exit $ftpRC
