[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5786
  • Last Modified:

How to create batch script to copy folders over network?

I want to create a Windows batch script that will copy from one server to another over the network, but I don't know how I would authenticate with the batch script. Can someone please help with an example?
3 Solutions
You can do this using net use:

net use \\server\share password /user:domainname\user

Domainname is optional.

Then you could copy the file like so:

copy c:\temp\temp.txt \\server\share\dir
I'd use xcopy instead ...
log in with an admin account onto a computer that has robocopy installed (part of windows resource kit).  Make sure that the account logged in with has permissions in both locations.
click start>run> type cmd and press enter.

robocopy <source> <destination> /e /z

substituting \\<servername>\<share> for the "<source>" and "<destination>"

e.g. robocopy \\server01\share01 \\server02\share02 /e /z

the /e will copy all sub-directories including empty ones
the /z will copy the files in restartable mode

if you need more help, go here : http://en.wikipedia.org/wiki/Robocopy
its pretty accurate, or just type robocopy /? at cmd prompt.

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now