IBM Power

ftp.sh

Melting 2012. 6. 28. 15:01

#!/usr/bin/ksh
if [ $# -ne 5 ]; then
    echo " Usage: ftp.sh <ftp server ip> <ftp user> <ftp password> <target director> <source file> "
    echo "    ex. ftp.sh 10.10.20.101 root passwd /home/ftp_back /etc/hosts "
    exit 1
fi

source_full_path=${5}
source_file=`echo ${source_full_path} | awk -F"/" '{print$NF}'`
source_path=`echo ${source_full_path} | awk -F'/[^/]*$' '{print $1}'`

new_file_name="${source_file}_`date +\"%Y%m%d%H%M%S\"`"

ftp -n ${1}  <<! >> ftp.log

        user ${2} ${3}
        lcd ${source_path}
        cd ${4}
        as

        put ${source_file} ${new_file_name}
        bye
!