Given a source and destination directory, the following function will copy contents between the two locations. Generally speaking, this isn't the code I use myself. I'll generally log into another remote server using PHP's FTP functions ... although the same principles apply.
To copy a single file, use PHP's copy() function. It's requires a path (or URL) to your source and path to a destination location. Because filenames are required, you may alter the name of the destination file.
This function will recursively copy all contents of a directory.
If you find that the source directory has a lot of content and is large in size (causing the copy to time out), you can use the following to potentially fix your problem. The value you set will be the script maximum execution time.
If you get an error message because your server is configured in safe-mode, try this rather than the above:
A value of '0' will set the execution timeout limit to 'infinity'.