#!/bin/sh

################################################################################
##                                                                            ##
## Copyright (c) International Business Machines  Corp., 2005                 ##
##                                                                            ##
## 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    ##
##                                                                            ##
##                                                                            ##
################################################################################
#
# File:
#   ftp-download-stress01-rmt
#
# Description:
#   This is the remote script for ftp-download-ipv${IP_VER}-stress01
#
# Author:
#   Mitsuru Chinen <mitch@jp.ibm.com>
#
# Arguments:
#   $1:	ip address of the server
#   $2: filename to download
#
# Exit Value:
#    0: Success
#   >0: Fail
#
# History:
#	Oct 19 2005 - Created (Mitsuru Chinen)
#
#-----------------------------------------------------------------------
# Uncomment line below for debug output.
#trace_logic=${trace_logic:-"set -x"}
$trace_logic

# Check the arguments
if [ $# -ne 2 ]; then
    echo "Usage: $0 server_ipaddr filename"
    exit 1
fi
server_ipaddr="$1"
filename="$2"

echo $server_ipaddr | fgrep ':' >/dev/null 2>&1
if [ $? -eq 0 ]; then
    server_ipaddr='['$server_ipaddr']'
fi

# Check the curl command is available
which curl >/dev/null 2>&1
if [ $? -ne 0 ]; then
    echo "The remote host does not have curl command."
    exit 1
fi

#
# Download the test file
#
curl -g "ftp://${server_ipaddr}/${filename}" -o /dev/null >/dev/null 2>&1
if [ $? -ne 0 ]; then
    echo "Failed to download the file from ftp://${server_ipaddr}/${filename}"
    exit 1
fi

exit 0
