Handling the decision to upload the FTP successfully

Source: Internet
Author: User


#登录FTP服务器获取指定文件
#$1: Server address
#$2: Account
#$3: Password
#$4: File path name
#$5: Local File path name
#$6: Local file name

#判断ftp上传结果:
#获取上传后的远程文件大小重定向在本地文件tmp, the same as the local file size, the same as upload success, and finally delete the local record tmp;
#判断外部调用函数 (such as system) execution results:
#执行成功返回为上传的结果: 0, execution failed to return script execution result or system call Result: not 0, avoid external call always return success: 0;
#日志修改:
#上传后紧接着写日志 (Append Write), and the FTP log is more than 100M empty.


########################################################################

Get_file ()
{
#echo "$ $4 $ $6"
Gf_host=$1
Gf_user=$2
Gf_pass=$3
Gf_datpath=$4
Gf_locpath=$5
Gf_srcfile=$6
#上传文件
Ftp-in $GF _host >>ftp.log<<-EOF
Quote USER $GF _user
Quote PASS $GF _pass
Bin
CD $GF _datpath
LCD $GF _locpath
Mput $GF _srcfile
Dir $GF _datpath/$GF _srcfile tmp
Quit
Eof

Ftpsize= ' cat $GF _locpath/tmp |sed-n '/' $GF _srcfile '/P ' |awk ' {print $ '
Localsize= ' ls-l $GF _locpath/$GF _srcfile |awk ' {print $} '
#echo $FTPSIZE
#echo $LOCALSIZE

If ["$FTPSIZE"! = ""] && ["$FTPSIZE" = = "$LOCALSIZE"]; Then
Retcode=0
Else
retcode=125
Fi

RM-RF $GF _locpath/tmp

1>/dev/null
2>/dev/null
#return $?
Return $RETCODE
}
############################################################################################################### ##########

Get_log_line ()
{
Gll_time= ' Date ' +%y-%m-%d%x '
#GLL_PATH = ' pwd '/' $FILENAME '
Result=$1
If ["$RESULT" = = 0]
Then
str_result= "Success!"
Else
str_result= "Failed!"
Fi
echo "$GLL _time| Upload | Local file: $: $ | to | Target Host: $4:$5 | $STR _result ">>ftp.log
}


Clear_ftplog ()
{
Ftplogsize= ' du-m ftp.log |awk ' {print $} ' | | Cut-f 1-d "M" | Cut-f 1-d "." `
If [$FTPLOGSIZE-GT 100]; Then
echo "" >ftp.log
Fi
}


############################################################################################################### ######

Clear_ftplog "100"

Host= ""
User= ""
Pass= ""
Datpath= ""
Locpath= "L"
Srcfile= ""
Get_file "$HOST" "$USER" "$PASS" "$DATPATH" "$LOCPATH" "$SRCFILE"
Get_log_line "$?" "$LOCPATH" "$SRCFILE" "$HOST" "$DATPATH"



Handling the decision to upload the FTP successfully

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.