How to copy files and retain permissions of target folder

dowhatyoudo22
dowhatyoudo22 used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

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

Commented:
robocopy source destination /sec
Raymond PengSystems Engineer

Commented:
David is on point.

I generally use this syntax:

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

sample:
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

https://technet.microsoft.com/en-us/library/Cc733145.aspx?f=255&MSPPError=-2147217396
End-user support
Commented:
> ...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