批处理命令远程向外网服务器中拷贝文件,Windows实现远程文件拷贝执行批处理脚本...

使用PsExec.exe 文件进行远程批处理文件执行。

使用xcopy进行远程文件拷贝

1:RemoteDeployment_main.bat  修改该文件。 制定目标文件路径。

2:RemoteDeployment_run.bat 设置该文件, 填写需要部署的远程文件的 ip 及登录用户名密码

3: RemoteDeployment  将准备部署的文件放大该目录下。

4:点击执行RemoteDeployment_run.bat 批处理文件。 开始批量部署

RemoteDeployment_main.bat

@echo off

set TargetIP=%1

if "%TargetIP%" == "" (

set TargetIP=

)

set TargetUser=%2

if "%TargetUser%" == "" (

set TargetUser=

)

set TargetPwd=%3

if "%TargetPwd%" == "" (

set TargetPwd=

)

set RemoteFullPath=%4

if {%RemoteFullPath:~-1%}=={\} set RemoteFullPath=%RemoteFullPath:~0,-1%

if {%RemoteFullPath:~-1%}=={/} set RemoteFullPath=%RemoteFullPath:~0,-1%

set RemoteSymbol=%RemoteFullPath:~0,1%

set RemotePath=%RemoteFullPath:~2%

net use * /del /y

net use \\%TargetIP% %TargetPwd% /user:%TargetUser%

xcopy /Y /E RemoteDeployment\RemoteDeployment.bat \\%TargetIP%\%RemoteSymbol%$%RemotePath%\S5500T-simu_linked

::等待文件拷贝完成

set trycount=1

:whilecopy

echo 等待文件拷贝完成-----%trycount%

ping 127.0.0.1 -n 2 >nul

if exist \\%TargetIP%\%RemoteSymbol%$%RemotePath%\S5500T-simu_linked goto endwhilecopy

set /a trycount=%trycount%+1

if "%trycount%"=="10" goto endwhilecopy

goto whilecopy

:endwhilecopy

if not exist \\%TargetIP%\%RemoteSymbol%$%RemotePath%\S5500T-simu_linked (

echo 文件拷贝失败,退出>>Test_TEP.log

goto end

)

echo 文件拷贝成功>>Test_TEP.log

::执行

set trycount=1

:whileexec3

echo 第%trycount%次执行脚本

psexec \\%TargetIP% -u %TargetUser% -p %TargetPwd% -s -d -w %RemoteSymbol%:%RemotePath%\S5500T-simu_linked\ %RemoteSymbol%:%RemotePath%\S5500T-simu_linked\RemoteDeployment.bat

goto endwhileexec3

:endwhileexec3

echo 远程执行成功>>Test_TEP.log

goto end

:enderror

echo invalid parameter!

echo should be: RemoteIP RemoteUser RemotePwd FtpServerIp FtpServerPort FtpServerUser FtpServerPwd RemoteInstallSymbol RemoteInstallPath LocalInstallFilePath

goto end

:end

RemoteDeployment_run.bat

del /F /Q Test_TEP.log

call RemoteDeployment_main.batIP administratorHuawei@123c:\

5f9741c1d0d970fac5681ad141c7eb4d.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值