skip to Main Content

Got a bit of a specific problem here. I’m in the process of developing an automated script in PHP to aid in the creation of a demonstration web application in the event a customer wants a demo site setup.

I’m using a dedicated server running Plesk.

My intention is to create a new sub-domain, create a new database, copy the database from elsewhere, copy the site files from another folder and finally email the customer with their login credentials, etc.

I’m using the Plesk API RPC to create the sub-domain, database and database user which is all working perfectly. I have the database copying the schema from elsewhere and I have the email part working. The only part that is eluding me is the copying of the files from one folder to another.

The source folder is within the same ‘httpdocs’ folder as the destination folder. The initial problem I had was the open_basedir issue which I’ve rectified but now I’ve got the permission denied problem.

I know I can’t chmod with windows.
I’ve tried using xcopy via exec() which returns

string(13) "Access denied"

I’ve also tried both cacls and icacls, both of which give me a similar error of

string(57) "Successfully processed 0 files; Failed processing 1 files"

Short of giving the whole httpdocs folder write permissions I’m at a bit of a loss on how best to further approach this. Any advice/help would be much appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    I managed to solve my predicament using the following code;

        system('icacls "C:Inetpubvhostsdomain.ltdhttpdocsdestination_subdomain" /grant:r "USER_USERNAME":(OI)(CI)F');
        system('xcopy /y /z /e "C:Inetpubvhostsdomain.ltdhttpdocssource_subdomain" "C:Inetpubvhostsdomain.ltdhttpdocsdestination_subdomain"');
        system('icacls "C:Inetpubvhostsdomain.ltdhttpdocsdestination_subdomain" /grant:r "USER_USERNAME":(OI)(CI)RX');
    

    The first line sets full permissions for the chosen username on the destination folder.

    The second line uses xcopy to copy all folders and subfolders, even empty ones from the source folder to the destination folder.

    The third line resets the permissions for the destination folder back to read and execute only.


  2. This script is works for me:

    <?php
    
    echo(system('xcopy /Y /Z "C:Inetpubvhostsexample.tldhttpdocsindex.html" "C:Inetpubvhostsexample.tldhttpdocsindex2.html"'));
    

    You can use xcopy:

    C:Inetpubvhostsexample.tldhttpdocs>xcopy index.html index5.html
    Does index5.html specify a file name
    or directory name on the target
    (F = file, D = directory)? F
    C:index.html
    1 File(s) copied
    

    But not in all cases:

    C:Inetpubvhostsexample.tldhttpdocs>xcopy /O index.html index4.html
    Does index4.html specify a file name
    or directory name on the target
    (F = file, D = directory)? F
    Access denied
    0 File(s) copied
    

    Also you can use icacls:

    C:Inetpubvhostsexample.tldhttpdocs>icacls index3.html /grant ftp3:(F)
    processed file: index3.html
    Successfully processed 1 files; Failed processing 0 files
    

    You can even disable inheretence:

    C:Inetpubvhostsexample.tldhttpdocs>icacls index4.html /inheritance:r
    processed file: index4.html
    Successfully processed 1 files; Failed processing 0 files
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search