download

downloadFile()
{
    if [ $# -ne 4 ]
    then
        echo "Usage: downloadFile remote_host_name remote_host_userid remote_file_path local_file_path"
        return 1
    fi
    
    remote_host_name=$1
    remote_host_userid=$2
    remote_file_path=$3
    local_file_path=$4
    size_remote=
    size_local=
   
    result=$(ssh ${remote_host_userid}@${remote_host_name} "if [ -f ${remote_file_path} ];then echo 0;else echo 1;fi")
   
    if [ ${result} -ne 0 ]
    then
        logger 2 "Remote file ${remote_file_path} is not exists"
        return 1
    fi
   
    size_remote=$(ssh ${remote_host_userid}@${remote_host_name} "ls -rlt ${remote_file_path} | grep `basename ${remote_file_path}` | awk '{print $5}'")
   
    scp ${remote_host_userid}@${remote_host_name}:${remote_file_path} ${local_file_path}

    ls ${local_file_path}/`basename ${remote_file_path}` > /dev/null
    result=$?
   
    if [ ${result} -ne 0 ]
    then
        logger 2 "Local file ${local_file_path}/`basename ${remote_file_path}` is not exists,download failed"
        return 1
    fi
   
    size_local=$(ls ${local_file_path}/`basename ${remote_file_path}` | grep `basename ${remote_file_path}` | awk '{print $5}')

    if [ ${size_remote} -ne ${size_local} ]
    then
        logger 2 "Download error, remote file size is ${size_remote}, local file size is ${size_remote}"
        return 1
    fi
   
    logger 0 "Download file ${remote_file_path} to ${local_file_path} successfully"
    return 0
}
请使用浏览器的分享功能分享到微信等