共享一下(根据batcher提供类似的代码修改):- rem 格式:
- rem -rw-rw-rw- 1 user group 1004346458 Jan 3 18:43 2011_pwdll_20100102_2255.rar
- @echo off
- rem 指定FTP用户名
- set ftpUser=aaa
- rem 指定FTP密码
- set ftppass=aaa
- rem 指定FTP服务器地址
- set ftpIP=11.11.22.22
- rem 指定待删除的文件位于FTP服务器的什么位置
- set ftpFolder=/dat1
- rem 指定删除几天前的文件
- set DaysAgo=15
- set ftpDir=%temp%\TempDir.txt
- set ftpDel=%temp%\Tempdel.txt
- rem 假设本机日期格式为yyyy-mm-dd
- set FileY=%date:~0,4%
- call :DateToDays %date:~0,4% %date:~5,2% %date:~8,2% PassDays
- set /a PassDays-=DaysAgo
- call :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 bye
- start ftp -v -i -s:"%ftpDir%" %ftpIP%
- ping 127.1 -n 12
- >"%ftpDel%" echo.%ftpUser%
- >>"%ftpDel%" echo.%ftpPass%
- >>"%ftpDel%" echo bin
- >>"%ftpDel%" echo cd "%ftpFolder%"
- (for /f "usebackq skip=2 tokens=1-12 delims=_ " %%a in ("%temp%\Filelist.txt") do (
- if "%%k" leq "%DstYear%%DstMonth%%DstDay%" (
- echo del "%%i_%%j_%%k_%%l"
- )
- endlocal
- ))>>"%ftpDel%"
- >>"%ftpDel%" echo bye
- ping -n 5 127.1 >nul
- rem -rw-rw-rw- 1 user group 1004346458 Jan 3 18:43 2011_ptas_20100102_2255.rar
- rem start ftp -v -i -s:"%ftpDel%" %ftpIP%
- ping -n 6 127.1 >nul
- rem sdelete -p 1 "%ftpDel%"
- rem sdelete -p 1 "%ftpDir%"
- rem sdelete -p 1 "%temp%\Filelist.txt"
- goto :eof
- :DateToDays %yy% %mm% %dd% days
- setlocal ENABLEEXTENSIONS
- set yy=%1&set mm=%2&set dd=%3
- if 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%%%100
- set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
- set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
- endlocal&set %4=%j%&goto :EOF
- :DaysToDate %days% yy mm dd
- setlocal ENABLEEXTENSIONS
- set /a a=%1+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
- set /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/=5
- set /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
复制代码
|