rem filename : auto.bat rem function : auto login in and download from ftp://efi_testing:Pass_123@192.168.12.10/pxe to c:/temp
@echo off rem 指定FTP用户名 set ftpUser='efi_testing' rem 指定FTP密码 set ftpPass='Pass_123' rem 指定FTP服务器地址 set ftpIP=192.168.12.10 rem 指定待下载的文件位于FTP服务器的哪个目录 set ftpFolder=/pxe rem 指定从FTP下载下来的文件存放到本机哪个目录 set LocalFolder=C:/temp
rem filename: ftpget.bat rem function: auto login in and download from ftp://efi_testing:Pass_123@192.168.12.10/client to %cd%
@echo off
set host=192.168.12.10 set user=efi_testing set pass=Pass_123 set dirname=client set homedir=%cd% rem 生成FTP目录结构 ifexisttree.txt deltree.txt
set time_begin=%time:~0,-3% start /w cmd /c makeTree %dirname%0 del result*.txt
for /f "delims=/" %%iin (tree.txt) do ( rem 获取dirname的所有文件 rem ============================= cd%homedir% md%%i cd /d %%i
echo open %host%>ftp.txt echo user %user%%pass%>>ftp.txt echocd%%i>>ftp.txt rem mget *.* 下载所有文件,但不能下载无扩展名的文件; rem 如果使用mget * 可以下载所有文件,但会把子目录的文件也下载过来 echo mget *.*>>ftp.txt
echo bye>>ftp.txt ftp -i -n -s:ftp.txt del ftp.txt rem ==============================
) cd%homedir% deltree.txt
set time_end=%time:~0,-3% call :time_lapse echo All copy cost %hour_% hours %munite_% minutes %second_% seconds pause>nul goto :eof
:time_lapse :: 一定要按照 秒=>分钟=>小时 的顺序操作
for /f "tokens=1,2,3 delims=:" %%iin ("%time_begin%") do ( set /a hour_b=%%i set /a munite_b=%%j set /a second_b=%%k )
for /f "tokens=1,2,3 delims=:" %%iin ("%time_end%") do ( set /a hour_e=%%i set /a munite_e=%%j set /a second_e=%%k )
if%second_e%lss%second_b% ( set /a munite_e=%munite_e%-1 set /a second_e=%second_e%+60 ) set /a second_=%second_e%-%second_b% if%munite_e%lss%munite_b% ( set /a hour_e=%hour_e%-1 set /a munite_e=%munite_e%+60 ) set /a munite_=%munite_e%-%munite_b% if%hour_e%lss%hour_b% ( set /a hour_e=%hour_e%+24 ) set /a hour_=%hour_e%-%hour_b%
rem filename: maketree.bat rem function: generate ftp directory structure rem 调用方法 maketree dir1\dir2 n (n>=1) rem %1 == dir1\dir2 rem %2 == n @echo off
set /a treetime=%2+1 echo %1 >>tree.txt
echo open %host% > ftp%treetime%.txt echo user %user%%pass% >>ftp%treetime%.txt echocd %1 >>ftp%treetime%.txt
ftp -i -n -s:ftp%treetime%.txt |find "<DIR>">result%treetime%.txt for /f "tokens=2,3*" %%iin (result%treetime%.txt) do (start /w cmd /c Maketree.bat %1\%%k %treetime%) rem del result%treetime%.txt rem del ftp%treetime%.txt