Solved

why is exec ('xcopy /o') not working ?

Posted on 2006-06-12
11
2,241 Views
Last Modified: 2013-12-13
Hi.

To support automated installations on Windows 2003 Server running PHP 4.4.1, I need a script to copy a basedir. The code exec ('xcopy \\base \\newdir') with a lot of commandline options works just fine. The only exception is the parameter /o which is supposed to copy the correct rights to the new directory. I need this so I can set the correct rights on the basedir (cachedir needs write permissions, and so on). I've not yet been able to solve this, or find more information about this. How can I get PHP to set the correct rights (preferrably using xcopy) ? Any other way that works is also acceptable.
0
Comment
Question by:pritaeas
  • 6
  • 5
11 Comments
 
LVL 40

Expert Comment

by:RQuadling
ID: 16884543
The only issue is does the webserver have permissions to set permissions which MAY be beyond their level?

I would ask this question in the MS Networking / Security TA.

Do you get an error when you try to do the copy?

What is the exact command you are issuing?

Try something like ...

<?php
exec("xcopy C:\\Source\\*.* D:\\Dest /Y /E /S /C /O /R", $a_output, $i_errorlevel);
print_r($a_output);
echo "Errorlevel : $i_errorlevel\n";
?>

What is the output you get?
0
 
LVL 40

Accepted Solution

by:
RQuadling earned 500 total points
ID: 16884555
/H may also be wanted.
/V also to verify the files.
/F would be nice to see exactly the files copied.

An alternative approach could be to use the MS Windows Resource Toolkit program ROBOCOPY

This does more things.

I suspect there is a permissions issue either with the user running the script (i.e. the webserver) or with the destination directory. I suspect that the webserver will need to have permission to set permissions/owners/acls. Maybe.
0
 
LVL 6

Author Comment

by:pritaeas
ID: 16884630
I have all the params you mention. I'll have a look at robocopy and the permissions.

As long as I don't use /o the script works just fine. If I include /o the I get CGI Error. The specified application misbehaved by not returning a complete set of HTTP headers, and nothing is copied.
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 16884681
Can you try the script from the command line ?

Try adding some output buffering and saving that first.

<?php
echo 'About to start output buffering<br />';
ob_start();
exec("xcopy C:\\Source\\*.* D:\\Dest /Y /E /S /C /O /R", $a_output, $i_errorlevel);
print_r($a_output);
echo "Errorlevel : $i_errorlevel\n";
$s_output = ob_get_flush();
$fp = fopen('./xcopy.log', 'rt');
fwrite($fp, $s_output);
fclose($fp);
echo $s_output;
?>
0
 
LVL 6

Author Comment

by:pritaeas
ID: 16884825
Tried robocopy and so the following in the output:

You do not have the Manage Audit user right.

That must be the problem, I'll look into it with the sysop here how to set this.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 40

Expert Comment

by:RQuadling
ID: 16884835
Aha!
0
 
LVL 6

Author Comment

by:pritaeas
ID: 16884978
Looks like it is solved. I must do a final test to make sure. When I do, you get the points, for pointing me to robocopy. Excellent tool: using /SEC param solved my problem.
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 16884990
ROBOCOPY is a great tool. Once you get that working, you will probably find that xcopy /o will also work.
0
 
LVL 6

Author Comment

by:pritaeas
ID: 16885007
No. xcopy /o still does not work. Robocopy /sec does. I think xcopy /o is equivalent to robocopy /copy:sou. I need only rights for /copy:s apparently.
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 16885150
Ok.

If you are copying a LOT of files, then using ROBOCOPY to create zero sized entries first is a good idea (so I've been told). It seems to work faster overall and results in less fragmentation.
0
 
LVL 6

Author Comment

by:pritaeas
ID: 16885170
Thanks for the info.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to dynamically set the form action using jQuery.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now