声明:博客内所有技术性文章都是由作者本人工作经验的总结, 实现过程中有搜索资料为参考的绝不涉嫌抄袭,均为个人习惯的总结。

我得工作中需要经常从ftp下载文件,解压缩文件,然后拷贝文件,所以写了一个批处理来实现,以下为具体的内容

@echo off //关闭执行时的命令显示
setlocal

set currentdir=%~dp0
set mydate=%date:~0,4%%date:~5,2%%date:~8,2%
set filedir=D:\RMMSoft\Server\AdminServer //设置用到的变量
 

echo;%currentdir%
echo;%mydate%
echo;================================================================================
echo;===================Environment variable has set succeed=========================
echo;================================================================================
pause

::以下是ftp下载的内容

(
echo;open xxx.xxx.xxx.xxx
echo;user rmmsoftuser
echo;8ik,9ol.
echo;cd "SetupAll_Products\Publish_Setup\YZ\Server"
echo;prompt //取消跟桌面的交互动作,直接覆盖
echo;get admin%mydate%.rar

::echo;put AcitvityLogServer\log\TServer%mydate%.log 2222222\log\acitvity\TServer%mydate%.html //这里是上传文件的命令格式
::echo;put Rmmsoft.RimsServer\log\RIMSServer%mydate%.log 2222222\log\rims\RIMSServer%mydate%.html //这里是上传文件的命令格式

echo;bye
) > "%currentdir%FTP_Admin.ftp" //输出一个临时文件

ftp -n -s:"%currentdir%FTP_Admin.ftp" 执行刚才输出的文件
echo;================================================================================
echo;====================Download remote files has completed=========================
echo;================================================================================
pause

::以下为解压文件
"C:\Program Files (x86)\WinRAR\Rar.exe" X /Y %currentdir%admin%mydate%.rar
echo;================================================================================
echo;======================Extract files complete succeed============================
echo;================================================================================
pause

::以下为备份现有的文件
if exist %filedir%\backup\%mydate% (
echo "Bacup has completed"
) else (
mkdir %filedir%\Backup\%mydate%
copy %filedir%\* %filedir%\Backup\%mydate% /y
)
echo;================================================================================
echo;====================Backup files has complete succeed===========================
echo;================================================================================
pause
 

::以下为停止服务 覆盖文件 启动服务
net stop Rmmsoft.AdminServer

xcopy %currentdir%src\* "%filedir%\*" /s /y /EXCLUDE:exclude.txt

net start Rmmsoft.AdminServer


echo;================================================================================
echo;=============Update files and start services complete succeed===================
echo;================================================================================
endlocal
echo on