首页 > 编程 > BAT > 正文

批处理bat下载FTP服务器上指定天数之前的文件

2020-07-26 20:14:48
字体:
来源:转载
供稿:网友
@echo offrem 指定FTP用户名set ftpUser=asxrem 指定FTP密码set ftpPass=asx-asxrem 指定FTP服务器地址set ftpIP=172.19.103.7rem 指定待下载的文件位于FTP服务器的什么位置set ftpFolder=/export/home/PROD/ntcdatarem 指定从FTP下载下来的文件存放到什么地方set LocalFolder=E:/Temprem 指定下载几天前的文件set DaysAgo=1set ftpDir=%temp%/TempDir.txtset ftpDown=%temp%/TempDown.txtrem 假设本机日期格式为yyyy-mm-ddset FileY=%date:~0,4%call :DateToDays %date:~0,4% %date:~5,2% %date:~8,2% PassDaysset /a PassDays-=DaysAgocall :DaysToDate %PassDays% DstYear DstMonth DstDay>"%ftpDir%" echo,%ftpUser%>>"%ftpDir%" echo,%ftpPass%>>"%ftpDir%" echo bin>>"%ftpDir%" echo cd "%ftpFolder%">>"%ftpDir%" echo dir * "%temp%/FileList.txt">>"%ftpDir%" echo byestart ftp -v -i -s:"%ftpDir%" %ftpIP%rem 根据实际情况自行调节延迟时间ping -n 200 127.1 >nulfindstr /i ":*/.SWM$" "%temp%/FileList.txt">"%temp%/FileDate.txt"findstr /i ":*/.TWM$" "%temp%/FileList.txt">>"%temp%/FileDate.txt"findstr /i ":*/.OWM$" "%temp%/FileList.txt">>"%temp%/FileDate.txt">"%ftpDown%" echo.%ftpUser%>>"%ftpDown%" echo.%ftpPass%>>"%ftpDown%" echo bin>>"%ftpDown%" echo cd "%ftpFolder%"(for /f "usebackq tokens=1-9 delims= " %%a in ("%temp%/FileDate.txt") do (  setlocal enabledelayedexpansion  if "%%f" equ "Jan" (    set FileM=01  ) else if "%%f" equ "Feb" (    set FileM=02  ) else if "%%f" equ "Mar" (    set FileM=03  ) else if "%%f" equ "Apr" (    set FileM=04  ) else if "%%f" equ "May" (    set FileM=05  ) else if "%%f" equ "Jun" (    set FileM=06  ) else if "%%f" equ "Jul" (    set FileM=07  ) else if "%%f" equ "Aug" (    set FileM=08  ) else if "%%f" equ "Sep" (    set FileM=09  ) else if "%%f" equ "Oct" (    set FileM=10  ) else if "%%f" equ "Nov" (    set FileM=11  ) else if "%%f" equ "Dec" (    set FileM=12  )  set FileD=10%%g  set FileD=!FileD:~-2!  if "!FileM!" equ "%DstMonth%" (    if "!FileD!" equ "%DstDay%" (     echo get "%%i" "%LocalFolder%/%%i"    )  )  endlocal))>>"%ftpDown%">>"%ftpDown%" echo byestart ftp -v -i -s:"%ftpDown%" %ftpIP%goto :eof:DateToDays %yy% %mm% %dd% dayssetlocal ENABLEEXTENSIONSset yy=%1&set mm=%2&set dd=%3if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)set /a dd=100%dd%%%100,mm=100%mm%%%100set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633endlocal&set %4=%j%&goto :EOF:DaysToDate %days% yy mm ddsetlocal ENABLEEXTENSIONSset /a a=%1+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=aset /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)endlocal&set %2=%yy%&set %3=%mm%&set %4=%dd%&goto :EOF
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表