I have to create a Windows XP batch file to copy files from a series of computers into a directory on another machine.

I've a text file with our internal LAN IPs like this:

171.10.2.2 
171.10.3.2
etc.

I have to copy all files from : \\171.10.2.2\c$\mydir\*.txt to \\myserver\mydir

link|improve this question

feedback

1 Answer

up vote 0 down vote accepted

for /f can iterate over lines in a file. xcopy can use UNC paths when copying.

Take the following as a starting point:

for /f %%x in (ips.txt) do xcopy \\%%x\C$\mydir\*.txt \\myserver\mydir

If you need a specific user/password on the other server I think the only good way to do would be to mount those as drives:

for /f %%x in (ips.txt) do (
    net use X: \\%%x\C$ <password> /user:<username>
    xcopy X:\mydir\*.txt Y:\
    net use X: /DELETE
)
link|improve this answer
Thank you. I've only one problem: can i insert my user and password (user credentials) to prevent the request by the client and server ? Thanks – stighy Mar 29 '11 at 12:00
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.