、主要脚本ftpget.bat,更改前4个变量的相关信息,该脚本调用makeTree.bat,请参见2
rem FTP服务器地址
set host=10.1.103.10
rem FTP登入名,如果匿名不用改
set user=anonymous
rem FTP登入密码,如果匿名不用改
set pass=123456
rem 需要下载的FTP目录,如果下载子目录以\分格
set dirname=目录1\子目录
set homedir=%cd%
rem 生成FTP目录结构
del tree.txt
start /w cmd /c makeTree %dirname% 0
del result*.txt
for /f "delims=/" %%i in (tree.txt) do (
rem 获取dirname的所有文件
rem =============================
cd %homedir%
md %%i
cd /d %%i
echo %user%>ftp.txt
echo %pass%>>ftp.txt
echo cd %%i>>ftp.txt
rem mget *.* 下载所有文件,但不能下载无扩展名的文件;
rem 如果使用mget * 可以下载所有文件,但会把子目录的文件也下载过来
echo mget *.*>>ftp.txt
echo bye>>ftp.txt
ftp -i -A -s:ftp.txt %host%
del
rem ==============================
)
cd %homedir%
del tree.txt
2、maketree.bat,生成FTP目录树
rem 生成FTP目录结构
rem 调用方法 maketree dir1\dir2 n (n>=1)
rem %1 == dir1\dir2
rem %2 == n
set /a treetime=%2+1
echo %1 >>tree.txt
echo %user% >ftp%treetime%.txt
echo %pass% >>ftp%treetime%.txt
echo cd %1 >>ftp%treetime%.txt
echo dir >>ftp%treetime%.txt
echo bye >>ftp%treetime%.txt
ftp -A -s:ftp%treetime%.txt %host% |find "
">result%treetime%.txt
for /f "tokens=2,3*" %%i in (result%treetime%.txt) do (start /w cmd /c Maketree.bat %1\%%k %treetime%)
del result%treetime%.txt
del ftp%treetime%.txt
阅读(2345) | 评论(0) | 转发(0) |