Use FTP to download files on Linux

Source: Internet
Author: User

Project requirements go to a file server to download the reconciliation file and save it to our system's front-facing server. Then the other vendors connected to our front-server, the file is taken away for parsing.

#!/bin/bash# @author:p ing# @function: This script is used to periodically download reconciliation files from a GC server to a pre-server in a third-party payment system # The reconciliation file will generate a. ok file when all downloads are completed # @instructions: 1. Timed task Implementation 2, script + date (shape as./ftpdownload.sh 20180820) # @associative directory:# log directory:/apache/unionpay/upload/logs# script directory:/apach e/unionpay/# Reconciliation file directory:/apache/unionpay/upload############################# #如下为定义的变量区 ########################### echo "********** file Download script starts execution ***********" >> $logDire $tradeday# Default Current system previous day if [!-n "$"];then tradeday= ' date-d " 1 days ago "+%y%m%d ' else tradeday=$1fi #定义服务器系统时间today = ' Date +%y%m%d ' #定义本地的下载存放目录localDire ="/apache/unionpay/upload/ "#定义日志目录logDire ="/apache/unionpay/upload/logs/"#日志文件后缀名suffixName =". Log "#截取日期subYesterday = ' expr substr ' $ Tradeday "3 6 ' #定义五个需要的文件名file1 =" ind "$subYesterday" 01ACOMN "file2=" ind "$subYesterday" 99ALFEE "file3=" IND "$ Subyesterday "99ILFEE" file4= "ind" $subYesterday "99AFCP" file5= "ind" $subYesterday "99IFCP" file6= "ind" $subYesterday " 01acomn.ok "# #确认文件 ################### #GC服务器信息 ###################### #FTP服务器地址ip =192.168.43.237#ftp account u=tppview#ftp password pass=tpp12#$ #GC服务器的目录地址remoteDire = "/home/gbatch/batch/file/" addtodire= "/0000/cup/ 04791922/"################### #函数定义 ##################### #ftpFun () {ftp-n <<eofopen $ipuser $u $               PASSBINARYPASSIVECD $remoteDire $tradeday$addtodire #远程服务器文件目录hashprompt off #关闭交互mget $ close byeeof}################## #下载对账文件 ################## #if [!-d "$logDire"];then mkdir "$logDire" echo "to create a log Catalog ====== $logDire "Fiif [!-d" $localDire $tradeday "];then mkdir" $localDire $tradeday "echo" Reconciliation files will be saved in the [$localDire $tra Deday] ">> $logDire $tradeday$suffixnameficd $localDire $tradeday//Switch directory if [-F" $localDire $tradeday "/" $file 6 Confirmation file [$file 6] ">> $logDire $tradeday$suffixname echo" Trading day [$tra];then echo directory [$localDire $tradeday]  Deday] The reconciliation file has been downloaded ">> $logDire $tradeday$suffixname Else echo" does not exist confirmation file [$file 6], start to download the reconciliation file "for FileName  In $file 1 $file 2 $file 3 $file 4 $file 5;do until[-F $localDire $tradeday "/" $fileName];d o echo "Start download reconciliation file ==================" $fileName >> $logDire  $tradeDay $suffixname ftpfun $fileName echo "Reconciliation file download process ends ==================" $fileName                       >> $logDire $tradeday$suffixname If [-F $localDire $tradeday "/" $fileName];then                       echo "Reconciliation file [$fileName] downloaded to local directory [$localDire $tradeday]" >> $logDire $tradeday$suffixname Else                        echo "did not get the reconciliation file ============" $fileName >> $logDire $tradeday$suffixname                       echo "Resume downloading files after 3 minutes of hibernation ===========" $fileName >> $logDire $tradeday$suffixname sleep 3s #休眠3分钟 Fi done-Done touch $localDire $tradeday "/" $file 6 echo "Trading day [$tradeDay] under the reconciliation file Download complete, the storage path is [$localDire $tradeday] ">> $logDire $tradeday$suffixnamefi######################################### #################################################################### #echo "********** script execution ends ***********" >> $logDire $tradeday 

Downloading files using FTP on Linux

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.