0

I want to copy files from one folder to multiple pc in the local network.

I want to add IP address in array list like below

set list=\\192.168.55.102
set list=%list%;\\192.168.55.103 
set list=%list%;\\192.168.55.104 
set list=%list%;\\192.168.55.105
set list=%list%;\\192.168.55.106

then, I will copy file to above IP's by following code. But the following code will do for 1 ip. It's working and copied the file to destination location

net use "\\192.168.55.102\c$\foldername" /user:%username% %password%
:copy
copy "C:\Desktop\Update" "\\192.168.55.102\c$\foldername"
IF ERRORLEVEL 0 goto disconnect
goto end
:disconnect 
net use "\\192.168.55.102\c$\foldername" /delete
goto end
:end

I tried like below, but it doesn't work

@echo off
for %a% in (%list%) do (  
    net use %a%\foldername /user:%username% %password%
    :copy
    copy "C:\Desktop\Update" %a%\foldername
    IF ERRORLEVEL 0 goto disconnect
    goto end
    :disconnect 
    net use %a%\foldername /delete
    goto end
    :end
)
0

1 Answer 1

1

Create a variable (not array) and add the IP's separated by space, comma or semicolon. Then connect to IPC$ to allow authentication, copy the file(s) and then remove the IPC$ share:

@echo off
set "list=192.168.55.102 192.168.55.103 192.168.55.104 192.168.55.105 192.168.55.106"
for %%i in (%list%) do (
    net use "\\%%i\IPC$" /user:%username% %password%
    copy "C:\Desktop\Update" "\\%%i\foldername"
    net use /d "\\%%i\IPC$"
)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.