① 如果我理解没错,远端目录,最深层的那个子目录(名称是日期)的那个,每天都是变的;你要下载的是里面的文件(不含子目录);文件下载到本地E:\dzyl下,而且目录也是按服务器上的日期创建。
② 批处理固定每天运行,从服务器前一天的目录下载文件。
如果理解正确,那么下面的代码可以实现(已测试过),ip地址你需要修改!你的 *** 作系统如果是英文,也需呀修改(具体看脚本中的提示)
@echo off & setlocal enabledelayedexpansionset "ftp_site=19.6.5.34"
set "ftp_id=pracq"
set "ftp_pwd=123456"
set "ftp_remote_dir=/ftp/bos/at/pracq/"
set "ftp_local_dir=E:\dzyl"
:100
set "ftpcmd={{%random%}}.ftp"
if exist %ftpcmd% goto 100
:: 英文系统用下面这个,把下面一行中的::去除
::set "today=%date:~6,4%%date:~0,2%%date:~3,2%"
:: 中文系统用下面这个,如果是英文,在下面一行句首添加::
set "today=%date:~0,4%%date:~5,2%%date:~8,2%"
set today=!today:~0,4!-!today:~4,2!-!today:~-2!
call :Date2Day !today! 1 Yesterday
set ftp_remote_dir=!ftp_remote_dir!!yesterday!
> %ftpcmd% echo open !ftp_site!
>>%ftpcmd% echo !ftp_id!
>>%ftpcmd% echo !ftp_pwd!
>>%ftpcmd% echo cd !ftp_remote_dir!
>>%ftpcmd% echo bye
for /f %%i in ('ftp -s:%ftpcmd%') do if {%%i}=={550} (
echo Remote directory does not exist!
goto end
)
set ftp_local_dir=!ftp_local_dir!\!yesterday!
md !ftp_local_dir! 1>nul 2>&1
if not exist !ftp_local_dir! (
echo Local directory creating error!
goto end
)
> %ftpcmd% echo open !ftp_site!
>>%ftpcmd% echo !ftp_id!
>>%ftpcmd% echo !ftp_pwd!
>>%ftpcmd% echo cd !ftp_remote_dir!
>>%ftpcmd% echo lcd !ftp_local_dir!
>>%ftpcmd% echo binary
>>%ftpcmd% echo prompt n
>>%ftpcmd% echo mget *.*
>>%ftpcmd% echo bye
set /a count=0
for /f %%i in ('ftp -s:%ftpcmd%') do (
if {%%i}=={226} set /a count=!count%+1
)
if !count! gtr 0 (
echo Done. !count! file^(s^) downloaded.
) else (
echo No file has been downloaded.
)
goto end
:Date2Day
::call :Date2Day 2007-11-12 2 Day
@echo off&setlocal
for /f "tokens=1-3 delims=/-:\, " %%a in ('echo/%~1') do (
set /a yy=%%a,mm=100%%b%%100,dd=100%%c%%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
set /a i=j-%~2,a=i+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 %~3=%yy%%f%%mm%%f%%dd%&
goto:eof
:end
if exist %ftpcmd% (type nul>%ftpcmd%&&del /f /q %ftpcmd% 1>nul 2>&1)
endlocal &@echo on
测试运行结果:
Done. 5 file(s) downloaded.1.新建一个批处理,里面的内容:@echo off
ftp -s:ftp.txt
2.建立一个ftp.txt,内容:
open 192.168.1.117
123
789
mget \音乐\a.mp3 e:\
mget \资料\文档\wor.txt e:\
bye
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)