需要将文件mktdt00.txt、cpxx0926.txt文件通过ftp每隔20秒同步到外网,其中cpxx0926.txt文件名中带有当天日期。
下面是通过ftp命令来实现:
@echo off
Title 文件同步程序,请勿关闭!
:again
set date=%date:~5,2%%date:~8,2%
echo open 192.168.100.112>%cd%\mktdt00.txt
echo test>>%cd%\mktdt00.txt
echo justin>>%cd%\mktdt00.txt
echo cd mktdt00>>%cd%\mktdt00.txt
echo put M:\mktdt00.txt>> %cd%\mktdt00.txt
echo cd ../SZFILE>>%cd%\mktdt00.txt
echo put N:\SHFILE\cpxx%date%.txt>>%cd%\mktdt00.txt
echo bye>>%cd%\mktdt00.txt
ftp -s:%cd%\mktdt00.txt
echo %Date:~0,4%-%Date:~5,2%-%Date:~8,2% %Time:~0,2%:%Time:~3,2%:%Time:~6,2%更新完成,20s后更再新......
del %cd%\mktdt00.txt /q
ping -n 20 127.0.0.1 >nul
goto again
set date=%date:~5,2%%date:~8,2% //设定变量,bak为当前日期,例如0926
echo open 192.168.100.112>%cd%\mktdt00.txt //ftp服务器地址 ,写入到当前目录mktdt00.txt文件
echo test>>%cd%\mktdt00.txt //ftp帐号,注意test后面紧跟>>,不能有空格等
echo justin2016>>%cd%\mktdt00.txt //ftp帐号,注意后面紧跟>>,不能有空格等
echo cd mktdt00>>%cd%\mktdt00.txt //切换目录
echo put M:\mktdt00.txt>> %cd%\mktdt00.txt
echo cd ../SZFILE>>%cd%\mktdt00.txt
echo put N:\SHFILE\cpxx%date%.txt>>%cd%\mktdt00.txt
echo bye>>%cd%\mktdt00.txt
ftp -s:%cd%\mktdt00.txt //从当前目录mktdt00.txt读取信息
echo %Date:~0,4%-%Date:~5,2%-%Date:~8,2% %Time:~0,2%:%Time:~3,2%:%Time:~6,2%更新完成,20s后更再新......
del %cd%\mktdt00.txt /q //删除mktdt00.txt文件,也可以不删除,因为第一部是>覆盖,不是叠加>>