Hello,

I have to set up about 40 gateway/doorway sites for a client. I want to set them up so they can be updated without me having to log into each one every time a change needs to be made.

I have an index page system all worked out so each gateway site can have it's own customized text etc using a single file on the main site.

BUT what I need now is to be able to store a folder with images etc on each of these gateway sites and have this folder of images/files be updated by a folder on the main site.

So lets say I have this folder on the main site:

www.mainsite.com/filefolder

... and filefolder contains:

image1.jpg
page.html
image2.gif

Now what I'd like to have is a script in each of the 40 gateway sites which would grab the folder "filefolder" from mainsite.com, and make an exact duplicate of that folder in the site the script resides on.

So if I had 3 gateway sites with this script:

www.gateway1.com/getfolder.php
www.gateway2.com/getfolder.php
www.gateway3.com/getfolder.php

... after the script was executed on each one the sites, they would now have an exact duplicate of "filefolder" from mainsite.com...so:

www.gateway1.com/filefolder
image1.jpg
page.html
image2.gif

www.gateway2.com/filefolder
image1.jpg
page.html
image2.gif

www.gateway3.com/filefolder
image1.jpg
page.html
image2.gif

Now each time the script (getfolder.php) is run, the script should delete "filefolder" if it exists from the site it's on and again grab and duplicate "filefolder" and it's contents from mainsite.com.

In short:

Execute Script:
www.gateway2.com/getfolder.php
Script Deletes Folder(if exists)
www.gateway2.com/filefolder <- delete
Script Grabs Folder And It's Contents From Main Site
www.mainsite.com/filefolder
Script Duplicates This Folder And It's Contents On It's Gateway Site
www.gateway2.com/filefolder <- create

Does anyone have an idea of how I could go about creating a script that would do this? I mean it sounds simple - copy a folder from one site and duplicate it on another - but I have no experience with creating/delete files and folders with PHP, especially when grabbing the files and folder from a different site.

I've checked several script sites and I can't find anything that does exactly what I'm looking for.

Any help with this would be greatly appreciated!!!!

Peter

    Hello lucasrd,

    I believe so, PHP Info reads "FTP Support - Enabled"

      I believe he means are you running an FTP server on these gateway machines, and would you be able to login and perform these actions (i.e. do you have permission).

        Oops, he gave this link:

        http://us3.php.net/manual/en/ref.ftp.php

        So I thought he was asking if I had PHP's FTP features available.

        But either way, yes each gateway site has an FTP account by default and I would have full access to all of them.

        PHP's FTP abilities look interesting though. I haven't seen any examples yet that would copy an entire folder. Only ones that get a single file by name. Looks promising though....

          This script looks interesting. Except I have to figure out how to modify it so it will GET and CREATE an entire directory instead of just a single file.

          <?php
          
          function ftp_copy($source_file, $destination_file)
          {
          	$ftp_server = 'ftp.server.com';
          	$ftp_user = 'login';
          	$ftp_password = 'password';
          
          $conn_id = ftp_connect($ftp_server);
          $login_result = ftp_login($conn_id, $ftp_user, $ftp_password);
          
          if((!$conn_id) || (!$login_result))
          {
                  echo "FTP connection has failed!";
                  echo "Attempted to connect to $ftp_server for user $ftp_user";
          }
          
          $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
          ftp_close($conn_id); 
          
          if(!$upload)
          {
                 echo "FTP copy has failed!";
             return false;
          }
          else
          {
              return true;
          }	
          }
          
          ?>
            Write a Reply...