BIN_FILE="/nn/sbin/ttyw -mtm30"

if [ "$#" = "0" ] ; then
  echo "nsftp userid password server src dest to/from (additional args)" 
  exit 1
fi

USERID=$1
shift
PASSWORD=$1
shift
SERVER=$1
shift
SRC=$1
shift
DES=$1
shift

SRC=$USERID@$SERVER:$SRC 

/bin/mv -f /tmp/srg.fw /tmp/srg.fw.old
/bin/rm -f /tmp/srgfwftpstatus
/bin/rm -f $HOME/.ssh/known_hosts > /dev/null 2>&1
$BIN_FILE /usr/local/bin/sftp $SRC $DES "password:=$PASSWORD" "Password:=$PASSWORD" "The authenticity of host=yes" > /tmp/srgnsftplog 
RETURN_CODE=$?
if [ "$RETURN_CODE" = "0" ] ; then
  echo "Success" >> /tmp/srgnsftplog 
fi
echo "Return Code" $?>> /tmp/srgnsftplog
cat /tmp/srgnsftplog | grep "[Nn]o such file or directory" 
if [ $? -eq 0 ]; then
  echo 101 File not found  > /tmp/srgfwftpstatus
  echo end > /tmp/srgfwftplog
fi
cat /tmp/srgnsftplog | grep "[Cc]onnection timed out"
if [ $? -eq 0 ]; then
  echo 102 Server not found > /tmp/srgfwftpstatus
  echo end > /tmp/srgfwftplog
fi
cat /tmp/srgnsftplog | grep "[Pp]ermission denied" 
if [ $? -eq 0 ]; then
  echo 103 Wrong user name or password > /tmp/srgfwftpstatus
  echo end > /tmp/srgfwftplog
fi
test -a /tmp/srg.fw
if [ $? -eq 0 ]; then
  echo 200 File Transfer Ok > /tmp/srgfwftpstatus
else
  echo 301 File Transfer Failed > /tmp/srgfwftpstatus
fi
echo end > /tmp/srgfwftpcomplete

exit $RETURN_CODE
