You will make a PHP script that will copy the contents of a folder residing on server A to server B using using curl (AND fsockopen as a backup, if curl fails).
The script will consist of two parts of which one will reside on server A and the other on server B.
Let's call them "script A" and "script B".
Script B script will call script A. Script B will pass script A the name of the directory on server A where the files are located. Script A will then return a list of files withing that directory. Script B will then make a separate request for each file. Script A will return the contents and script B will create a file and write the content to it. Script B will repeat the process for all files from the list it received from script A.
In some cases files on server A can be stored in sub-directories. The file/directory structure must be replicated nevertheless.
Script B should know which are common text and binary files and save them as such.
A some sort of checking mechanism will have to be used to report any errors that may occur. If any errors whatsoever happen, the script B should store them in an array (for a later use, either to display them to the screen or write them to an error log file).
After the copying files/directories have to have permissions set. Permissions for certain file types will be saved in an array in script A (so that I can add new file types later, if necessary). Script B should therefore request the info about permissions of certain file types from script A.
Last thing: there should be a way to update the PHP code of the script B the way that script B calls script A for update of code and script A returns the code and script B writes that code either in itself (if that is even possible) or it writes it in external file that is then called by include().
As additional option (if, turned on in script B) script B should be able to delete all the files not existing in server A directory (therefore not reported in file list by script A).