下文中用upload.txt代替”上传命令.txt“,仅仅为了书写方便。
@echo off
> upload.txt echo open *.*.*.*
>>upload.txt echo user
>>upload.txt echo password
>>upload.txt echo prompt
>>upload.txt echo mput *
for /f "tokens=*" %%i in ('dir /ad/s/b') do (echo mkdir "%%i" >> upload.txt
echo cd "%%i" >> upload.txt
echo lcd "%%i" >> upload.txt
echo mput * >> upload.txt
echo lcd >> upload.txt)
总之,用微软这个弱智的ftp命令确实是挺恶心的,还是建议用lftp或者ncftp这一类功能更强的工具。
你可以试试用命令行调用一个FTP客户端,将要上传的目录以命令行参数传递给该程序,由它来完成所有子目录的同步.或者去找一个叫NcFTP的命令行FTP客户端,它可以通过命令行参数完成整个目录的上传下载工作.
@echo off
echo open 192.168.1.10>ftp.txt
echo user>>ftp.txt
echo password>>ftp.txt
echo prompt>>ftp.txt
echo mput *>>ftp.txt
for /f "tokens=*" %%i in ('dir/s/b/ad') do (
echo mkdir "%%~ni" >>ftp.txt
echo cd "%%~ni" >>ftp.txt
echo lcd "%%i" >>ftp.txt
echo mput * >>ftp.txt
echo cd ..>>ftp.txt)
ftp -s:ftp.txt