Link to home
Start Free TrialLog in
Avatar of torbenus
torbenusFlag for Denmark

asked on

SQL copying folder and keeping security settings

How do I copy a folder structure via an SQL SP and keeps the same security settings on the destination folders as on the source folders ?
When i make a copy now its security settings is always inherited from the parent security settings of the directory parent - i would like it remain as the original folder structure.
Right now im using this code to copy the folder structure :
 
DECLARE @FsObjId	INTEGER
DECLARE @Source 	VARCHAR(4096),
DECLARE @Destination	VARCHAR(4096),
 
SET @Source = '\\192.168.0.1\test\folderstructure'
SET @Destination= '\\192.168.0.2\test\customer\structure'
 
EXEC sp_OACreate 'Scripting.FileSystemObject', @FsObjId OUTPUT
EXEC sp_OAMethod @FsObjId, 'CopyFolder', NULL, @Source, @Destination, @OverWrite

Open in new window

Avatar of RiteshShah
RiteshShah
Flag of India image

well, you can use "XCOPY" command of DOS in SQL server to copy folder, it's file and subdirectory to other location.  You can use any of the DOS command by XP_cmdshell of SQL SERVER. You can have a liitle look of it from my blog link given below.

http://www.sqlhub.com/search?q=xp_cmdshell


Now, as long as security concern, it won't same as the source folder for SURE. there is no direct way to do so. you have to set proper permission for parent folder of destination so it will be inherited in the files and folder your copied, or write some script in .NET or may be in SQL Server which set the permission of file and folder after your copy it.
Avatar of Mark Wills
Could try movefolder - it might preserve the original ownership, however, I am fairly sure that it is going to inherit any conlicting ownership from it's parent.

Look at : http://msdn.microsoft.com/en-us/library/1c87day3(VS.85).aspx  for folder object properties
and then : http://msdn.microsoft.com/en-us/library/5tx15443(VS.85).aspx

I cannot recall any off the top of my head (and I am a fond user of OA), the scripting runtime libraries are not overflowing with information...

You may need to look outside the file or folder object and look at AD or other security pradigms.
Such as http://support.microsoft.com/default.aspx?scid=kb;EN-US;269159

Hope that helps...
ASKER CERTIFIED SOLUTION
Avatar of Jim P.
Jim P.
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes of course - good call jimpen. It will mean enabling xp_cmdshell which can be secure if managed, though, found most people play with OA to avoid xp_cmdshell type operations.