How to copy files and retain permissions of target folder

dowhatyoudo22 used Ask the Experts™
I need to create a process that will copy all .pdf files from one location (Windows Server 2003 directory) to another location (Windows Server 2008 R2) nightly. Once the files have been copied over I need them permissions of the target folder to be applied to them.

I tried to create a batch file that will be ran by Windows Scheduled Tasks nightly. The batch file simply copies the files from point A to point B. However the permissions of the target folder are not being applied. Because when I try to access any of the copied pdf files via a web application I have that views this directory I get an access denied error. If I simply go to the directory and refresh the permissions by taking them out and putting them back in for the account in question the error goes away.

Any suggestions?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

robocopy source destination /sec
Raymond PengSystems Engineer

David is on point.

I generally use this syntax:

robocopy source destination /mir /sec /w:1 /r:1 /log: "log file location.txt"

robocopy \\servername\fileshare1 D:\foldername /mir /sec /w:1 /r:1 /log:"log location"

/mir = mirrors (exact copy)
/sec = copies security attributes
/w:1 = wait one sec before trying
/r:1 = retry once
End-user support
> ...the permissions of the target folder are not being applied
Clarification: You want the permissions of the target, not the source permissions, to be applied. Correct? If so...

A plain robocopy w/o switches just copies files w/o permissions. i.e. robocopy \\server2003\share \\server2008\share "*.pdf". The permissions at the target are based on those of the target parent folder. You are probably using one or more of the security switches, e.g. /sec, /copyall, which copies the source permissions.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial