Windows Server and Linux server FTP fetch scripts

Source: Internet
Author: User
Tags ftp file save file ftp client

Linux (IP if for 11.11.0.1) from Linux (IP if 11.11.0.2) then need to 11.11.0.2 on the VSFTP is the FTP server, in 11.11.0.1 install FTP client,

http://download.csdn.net/detail/u012209894/9537732


#!/bin/sh########################################################################## this to execute the script manually, need to pass in the execution date, also can automatically execute # # ######################################################################## organization number (need to write dead original date can write dead timetmp can, If you need 20150202 Day data, re-run need to delete the JKSJ folder on the day of the file) set-eorgcode=883000# automatically enter the date of the previous days timetmp=$ (date-d "Yesterday" +%y%m%d) #read var #TIMETMP = $var # re-run need to delete the day file data cd/home/pasdb/doload/pasdata/jksj/rm-rf $TIMETMP # System Current date systime=$ (date ' +%y-%m-%d%h:%m:% S ') Nowdate=${systime:0:10}nowtime=${systime:11:8} #三十天以前的日期tendays =$ (date-d "days Ago" +%y%m%d) # if the format is : 2010-07-07if test "${#TIMETMP}" = 10then yyy=${timetmp:0:4} mmm=${timetmp:5:2} Ddd=${timetmp:8:9} indate= $YYY $MMM $ddd# If the input date format is: 20100707else indate= $TIMETMPfi # Modified date format: 2010-07-07yyy=${indate:0:4}mmm=${indate:4:2}ddd=${ indate:6:7}procdate= $YYY "-" $MMM "-" $DDDYEARBEGIN = $YYY "-01-01" # the day before date format: 2010-05-20#dayago=$ (date-d "$PROCDATE-1 Days "+%y-%m-%d) #AGODATE =$ (date-d" $PROCDATE – 1 Days "+%y%m%d) #nMonBegDate =$ (date-d" $PROCDATE "+%y%m)" 01 "#nMEndLaDate =$ (date-d "$nMonBegDate-1 days +1 months" +%y%m%d) logyear= $YYYlogMonth = $MMMif ["$PROCDATE" \< "$NOWDATE "]then# Script storage directory datapath=/home/pasdb/doload #LOADPATH =/home/pasdb/doload/pas_load_core.sql procpath=/home/pasdb/do LOAD/PAS_PRO_FILE.SH#FTP Information: IP address: ftpip; user name: ftpname; password: ftppwd; FTP directory: Ftpdatapath; FTP Save file name: Ftpfile ftpip= "11.11.0.2" ftpname= "Sjff" ftppwd= "Sjff" ftpdatapath= "/home/sjff/core/add/" $INDATE F Tpfile_core= "Core_" $ORGCODE "_" $INDATE "_add.tar.z" #初始化标记值为0 loadflag=0# Create working directory CreateWorkspace () {if [!-E $DATAPATH "/pasdata"] then mkdir pasdata CD pasdata # Dbresult store execution result m  Kdir Dbresult # Zipdata store ftp downloaded zip data file mkdir zipdata mkdir zipdata/sjff mkdir            Zipdata/sjff "/" $INDATE # unzipdata Storage Execution Day m package decompression temporary storage directory mkdir unzipdata # log storage log file mkdir Log #CORE store CORE log files mkdir coremkdirJksjmkdir jksj "/" $INDATE #mkdir Log "/core/" $logYear #mkdir Log "/core/" $logYear "/" $logMonth Else            CD $DATAPATH "/pasdata" if [!-e Dbresult] then mkdir dbresult fi  if [!-e Zipdata] then mkdir zipdata fi if [!-e Zipdata/sjff            ] then mkdir zipdata/sjff fi if [!-e zipdata/sjff/$INDATE]                Then mkdir zipdata/sjff/$INDATE fi if [!-e Unzipdata] Then mkdir unzipdata fi if [!-e log] then mkdir log fiif [!- E jksj/$INDATE]thenmkdir jksj/$INDATEfi fi datapath= $DATAPATH "/pasdata"} #创建程序实现功能所需的目录空间 Createworksp Ace $DATAPATH logfile= $DATAPATH "/log/core_" $INDATE ". Log" dbresult= $DATAPATH "/dbresult" Daily_batch_last_date_core = $DBRESULT "/daily_batch_Last_date_core "daily_batch_begin_state_core= $DBRESULT"/daily_batch_begin_state_core "sql_result_core_load=$ Dbresult "/sql_result_core_load" if [!-e $DAILY _batch_last_date_core] then touch $DAILY _batch_last_date_cor  e fi if [!-e $DAILY _batch_begin_state_core] then touch $DAILY _batch_begin_state_core fi if [!-E $SQL _result_core_load] Then touch $SQL _result_core_load fi# write log writelog () {if [!-e $LOGFIL  E] then touch $LOGFILE fi if [""! = ""] then echo $ (date ' +%y-%m-%d %h:%m:%s ') "=======>" $ | Tee-a $LOGFILE fi}# ftp download data/usr/bin/ftp-n<<!open $FTPIPuser $FTPNAME $FTPPWDbinaryprompt OFFC D $FTPDATAPATHlcd $DATAPATH "/zipdata/sjff/" $INDATEmget "$FTPFILE _core" closebye!cd $DATAPATH "/zipdata/sjff/" $ Indatewritelog "Download ftp file is end." If [-F ' $FTPFILE _TPDM "]then#filesize=$ (ls-l $FTPFILE _core|awk ' {printf $} ') #FILESIZE =$ (awk beGIN ' {printf "%.3f", ' $FILESIZE '/(1024*1024)} ') #cd $DATAPATH "/pasdata/zipdata/sjff/" $INDATE #chmod 777 "$INDATE" tar-  ZXVF $FTPFILE _core-c/home/pasdb/doload/pasdata/unzipdatawritelog "Download ftp file is success and tar file to Unzipdata Success "MV"/home/pasdb/doload/pasdata/unzipdata/core_bdfmhqaa_ "$INDATE" _add_883.del "/home/pasdb/doload/pasdata /JKSJ "/" $INDATE/bdfmhqaa. Delwritelog "Copy required file to JKSJ success" #验证文件是否齐全cd/home/pasdb/doload/pasdata/jksj "/" $INDATEif [1! = $ (ls-a | w C-L)]thenwritelog "Today jksj file incomplete data" Cd/home/pasdb/doload/pasdata/jksjrm-rf $INDATEelsetouch Ok.datwrit ELog "Today jksj file complete data and create Ok.dat file" Ficd/home/pasdb/doload/pasdata/unzipdatarm-f *.delwritelog "D Elete Unzipdata file successfully "Cd/home/pasdb/doload/pasdata/logrm-f" Core_ "$tendays". Log "Writelog" Remove ten days Before log file successfully "Cd/home/pasdb/doload/pasdata/zipdata/sjffrm-rf $tendaysWriteLog" remove ten days before SJ FF file successfullY "loadflag=1elsewritelog" Download ftp file is fail,please Check the ftp file is exist? "        Loadflag=0fifi

Linux (IP if for 11.11.0.1) from Windows (IP if 11.11.0.2) then need to install the FTP server in 11.11.0.2, 11.11.0.1 FTP client, if the folder is the following method wget, take the file using the method above.

#!/bin/sh########################################################################## Script Description: Performance appraisal system end of day script file # This will execute the script manually , you need to pass in the execution date, or you can automatically execute ########################################################################## ( Need to write dead original date can write dead timetmp can, if you need 20150202 day of data, re-run need to delete the JKSJ folder that day file) set-e# automatically get yesterday's date timetmp=$ (date-d "Yesterday" +%y%m%d) # Manually enter yesterday date #read var#timetmp= $var # Day re-run get yesterday file need to delete yesterday file data if [!-e/xxpas/doload/jksj/] Then mkdir-p/xxpas /doload/jksj/else cd/xxpas/doload/jksj/rm-rf $TIMETMP fi #系统当前日期SYSTIME =$ (date ' +%y-%m-% D%h:%m:%s ') Nowdate=${systime:0:10} #NOWTIME =${systime:11:8} #三十天以前的日期tendays =$ (date-d "days Ago" +%y%m%d) # if the format is : 2010-07-07if test "${#TIMETMP}" = 10then yyy=${timetmp:0:4} mmm=${timetmp:5:2} Ddd=${timetmp:8:9} indate= $YYY $MMM $ddd# If the input date format is: 20100707else indate= $TIMETMPfi # Modified date format: 2010-07-07yyy=${indate:0:4}mmm=${indate:4:2}ddd=${ indate:6:7}procdate= $YYY "-" $MMM "-" $DDDYEARBEGIN = $YYY " -01-01" if ["$PROCDATE" \< "$NOWDATE"]then# script holds directory datapath=/xxpas/doload# initialization tag value is 0 loadflag=0# Create working directory CreateWorkspace () {if [!]            -E $DATAPATH "/JKSJ"] then mkdir JKSJ # Log holds log file mkdir log else CD $DATAPATH "/JKSJ" if [!-e log] then mkdir log fi fi Datap     Ath= $DATAPATH "/JKSJ"} #创建程序实现功能所需的目录空间 createworkspace $DATAPATH logfile= $DATAPATH "/log/xxjk_" $INDATE ". Log" #写日志        Writelog () {if [!-e $LOGFILE] then touch $LOGFILE fi if [""! = ""] then echo $ (date ' +%y-%m-%d%h:%m:%s ') "=======>" $ | Tee-a $LOGFILE fi}# ftp download data IP username Password change the folder Wget-r-nh-p/xxpas/doload/jksj ftp://11.11.0 for the day before. 2 "/" $INDATE--ftp-user=admini1--ftp-password=123cd $DATAPATH "/" $INDATEWriteLog "Download ftp file is end." #tar-zxvf $FTPFILE _core-c/xxpas/doload/jksj "/" $INDATE #gunzip-n $FTPFILE _corewritelog "Download ftp File is success and tar file to JKSJ success "#删除10天前文件cd/xxpas/doload/jksj/logrm-f" Xxjk_ "$tendays". Log "Writelog" Remov E ten days before log file successfully "Cd/xxpas/doload/jksjrm-rf $tendaysWriteLog" remove ten days before Sjff file suc cessfully "loadflag=1elsewritelog" Download ftp file is fail,please Check the ftp file is exist? " Loadflag=0fi

Use manual input date to cycle data on Linux

#!/bin/sh######################################################################### This can be manually executed script, need to pass the execution date, also can automatically execute # # # ####################################################################### organization number (need to write dead original date can write dead timetmp can, If you need 20150202 Day data, re-run need to delete the JKSJ folder on the day of the file) set-eorgcode=883000# automatically enter the day before the date #timetmp=$ (date-d "Yesterday" +%y%m%d) #liulei 20160531 add BeginRead varread endvardatebeg= $vardateend = $endvarbeg _s= ' date-d ' $datebeg "+%s ' end_s= ' date-d" $dateend " +%s ' While ["$beg _s"-le "$end _s"] dotimetmp= $beg _s #重跑需删除当天文件数据cd/home/pasdb/doload/addpasdata/jksj/rm-rf $TIME tmp# System Current Date systime=$ (date ' +%y-%m-%d%h:%m:%s ') Nowdate=${systime:0:10}nowtime=${systime:11:8} #十天以前的日期tendays =$ (    Date-d "days Ago" +%y%m%d) # If the format is: 2010-07-07if test "${#TIMETMP}" = 10then Yyy=${timetmp:0:4} mmm=${timetmp:5:2} Ddd=${timetmp:8:9} indate= $YYY $mmm$ddd# if the input date format is: 20100707else indate= $TIMETMPfi # Modified date format: 2010-07-07yyy=${indate: 0:4}mmm=${indate:4:2}ddd=${indate:6:7}procdate= $YYY "-" $MMM "-" $DDDYEARBEGIN = $YYY "-01-01 "# the day before date format: 2010-05-20#dayago=$ (date-d" $PROCDATE-1 Days "+%y-%m-%d) #AGODATE =$ (date-d" $PROCDATE-1 days "+%y%m%d ) #nMonBegDate =$ (date-d "$PROCDATE" +%y%m) "#nMEndLaDate =$ (date-d" $nMonBegDate-1 days +1 months "+%y%m%d) #logYear =$ Yyy#logmonth= $MMMif ["$PROCDATE" \< "$NOWDATE"]then# script to store the directory Datapath=/home/pasdb/doload #LOADPATH =/home/pasdb/do Load/pas_load_core.sql procpath=/home/pasdb/doload/pas_pro_file.sh#ftp Information: IP address: ftpip; user name: ftpname; password: FTPPWD; FTP directory: Ftpdatapath; FTP Save file name: Ftpfile ftpip= "11.11.0.2" ftpname= "Sjff" ftppwd= "Sjff" ftpdatapath= "/home/sjff/core/add/" $INDATE F Tpfile_core= "Core_" $ORGCODE "_" $INDATE "_add.tar.z" #初始化标记值为0 loadflag=0# Create working directory CreateWorkspace () {if [!-E            $DATAPATH "/addpasdata"] then mkdir addpasdata CD addpasdata # Dbresult Store execution Results            mkdir Dbresult # Zipdata store ftp downloaded zip data file mkdir zipdata mkdir zipdata/sjff mkdir ZIPDATA/SJFF"/" $INDATE # unzipdata Storage Execution Day m package decompression temporary storage directory mkdir unzipdata # Log storage log file mkdir log    #CORE store CORE log files mkdir coremkdir jksjmkdir jksj "/" $INDATE #mkdir Log "/core/" $logYear            #mkdir log "/core/" $logYear "/" $logMonth else CD $DATAPATH "/addpasdata" if [!-e Dbresult] Then mkdir dbresult fi if [!-e Zipdata] then MK            Dir zipdata fi if [!-e Zipdata/sjff] then mkdir ZIPDATA/SJFF            fi if [!-e zipdata/sjff/$INDATE] then mkdir zipdata/sjff/$INDATE fi            if [!-e Unzipdata] then mkdir unzipdata fi if [!-e Log] then mkdir log fiif [!-e jksj/$INDATE]thenmkdir jksj/$INDATEfi fi Datapa Th= $DATAPATH "/addpasdata"} #创建程序实现功能所需的目录空间 createworkspace $DATAPATH logfile= $DATAPATH"/log/core_ "$INDATE". Log "dbresult= $DATAPATH"/d Bresult "daily_batch_last_date_core= $DBRESULT"/daily_batch_last_date_core "daily_batch_begin_state_core=$ Dbresult "/daily_batch_begin_state_core" sql_result_core_load= $DBRESULT "/sql_result_core_load" if [!-e $DAILY _batch _last_date_core] then touch $DAILY _batch_last_date_core fi if [!-e $DAILY _batch_begin_state_core] t Hen Touch $DAILY _batch_begin_state_core fi if [!-e $SQL _result_core_load] then touch $SQL _result        _core_load fi# Write Log writelog () {if [!-e $LOGFILE] then touch $LOGFILE fi if [""! = ""] then echo $ (date ' +%y-%m-%d%h:%m:%s ') "=======>" $ | Tee-a $LOGFILE fi}# ftp download data/usr/bin/ftp-n<<!open $FTPIPuser $FTPNAME $FTPPWDbinaryprompt OFFC D $FTPDATAPATHlcd $DATAPATH "/zipdata/sjff/" $INDATEmget "$FTPFILE_core "CLOSEBYE!CD $DATAPATH"/zipdata/sjff/"$INDATEWriteLog" Download ftp file is end. " If [-F ' $FTPFILE _TPDM "]thentar-zxvf $FTPFILE _core-c/home/pasdb/doload/addpasdata/unzipdatawritelog" Download ftp fil E is success and tar file to Unzipdata success "MV"/home/pasdb/doload/addpasdata/unzipdata/core_bwfmatmd_ "$INDATE" _add_ 883.del "/HOME/PASDB/DOLOAD/ADDPASDATA/JKSJ"/"$INDATE/BWFMATMD. Delwritelog "Copy required file to JKSJ success" #验证文件是否齐全cd/home/pasdb/doload/addpasdata/jksj "/" $INDATEif [1! = $ (ls-a | WC-L)]thenwritelog "Today jksj file incomplete data" Cd/home/pasdb/doload/addpasdata/jksjrm-rf $INDATEelsetouch Ok.dat Writelog "Today jksj file complete data and create Ok.dat file" Ficd/home/pasdb/doload/addpasdata/unzipdatarm-f *.delwrit ELog "Delete unzipdata file successfully" Cd/home/pasdb/doload/addpasdata/logrm-f "Core_" $tendays ". Log" Writelog " Remove ten days before log file successfully "Cd/home/pasdb/doload/addpasdata/zipdata/sjffrm-rf $tendaysWriteLog" Remove Ten days before sjff file successfully "Loadflag=1elsewritelog" Download ftp file is fail,please Check the ftp file is exist? "        Loadflag=0fifi beg_s=$ ((beg_s+86400)) done
If the Windwos on the loop to use the data, now can only think of the date range within one months, because the date on the windowns is outside the month is more cumbersome

@echo on::------------------------------------------------------------------:: Example:call test.bat 20160101  20160110::------------------------------------------------------------------setlocal Enabledelayedexpansionset Startdate=%1set enddate=%2set ftp_server=11.11.0.2set ftp_user=admin1set ftp_password=admin1echo The current input date is 1:% Startdate%rem pauseset dy=%startdate:~,4%set dm=%startdate:~4,2%set dd=%startdate:~6,2%echo The current input date is:%dy%%dm%%dd%set Starttime=%time:~0,2%:%time:~3,2%:%time:~6,2%rem Pauseset Pas_date=%dy%%dm%%dd%:startd:set PAS_ROOT=D:\DATA\ Jksjif not exist%pas_root% mkdir%pas_root%set ftp_cmd_file=%pas_root%\ftpcmd.txtset Pas_data_dir=%pas_root%\%pas_ Date%if not exist%pas_data_dir% mkdir%pas_data_dir%echo folder address%pas_data_dir%rem get data from FTP Echo open%ftp_server%>%ftp _cmd_file%echo%ftp_user%>>%ftp_cmd_file%echo%ftp_password%>>%ftp_cmd_file%echo ascii>>%FTP_ Cmd_file%echo literal Pasv>>%ftp_cmd_file%echo prompt >>%ftp_cmd_file%echo CD%pas_date%>>%ftp_cmd_file%echo LCD%pas_date%>>%ftp_cmd_file%echo mget *.*>>%ftp_cmd_file%echo close> >%ftp_cmd_file%echo Bye>>%ftp_cmd_file%ftp-s:%ftp_cmd_file%c:echo Decompression Start &GT;&GT;%PAS_DATA_DIR%\GETOK.DATC : \ "program Files" \winrar\winrar.exe e%pas_data_dir%\*.zip%pas_data_dir% echo decompression complete >>%pas_data_dir%\ Getok.datset endtime=%time:~0,2%:%time:~3,2%:%time:~6,2%echo FTP Download data start time:%starttime%, end time:%endtime%echo FTP Download Data start time:%starttime%, End time:%endtime% >>%pas_data_dir%\getok.datd:cd%pas_data_dir% if exist *.ok (Echo%pas_ Date%>>%pas_data_dir%\jksjok.dat) echo exists >>%pas_data_dir%\getok.datset/a "PAS_DATE+=1" Echo now date:% Pas_date%echo now Enddate:%enddate%rem pauseif "%enddate%" NEQ "%pas_date%" Goto startexit




Windows Server and Linux server FTP fetch scripts

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.