Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2003
    Location
    UK
    Posts
    27

    Post Unanswered: RE: Copy Directory

    Hi All,

    Hope u all had a merry xmas..... :-)

    This one will probably be easy for the php gurus...... but it's had me puzzled for nearly two hours.....

    how do you copy a directory from ftp to another....????


    i hav this script twhich copies a single file..... but how do i copy the whole directory.... ????

    <?php
    $source_file = "ftp://usernameassword@ftp.URL1.com/wedding/my_file.htm";
    $destination_file = "ftp://usernameassword@ftp.URL2.com/wedding/my_file.htm";

    if (file_exists($destination_file))
    {
    unlink ($destination_file);
    }

    copy ($source_file, $destination_file);


    ?>


    all help is much appriciated
    Phil

  2. #2
    Join Date
    Jul 2003
    Location
    Jersey
    Posts
    11

    Re: RE: Copy Directory

    Originally posted by philhowell
    Hi All,

    Hope u all had a merry xmas..... :-)

    This one will probably be easy for the php gurus...... but it's had me puzzled for nearly two hours.....

    how do you copy a directory from ftp to another....????


    i hav this script twhich copies a single file..... but how do i copy the whole directory.... ????

    <?php
    $source_file = "ftp://usernameassword@ftp.URL1.com/wedding/my_file.htm";
    $destination_file = "ftp://usernameassword@ftp.URL2.com/wedding/my_file.htm";

    if (file_exists($destination_file))
    {
    unlink ($destination_file);
    }

    copy ($source_file, $destination_file);


    ?>


    all help is much appriciated
    Phil
    PHP Code:

    $loc 
    "...";
    $dir opendir($loc) or die ("Open Failed!");

    while ((
    $file readdir($source_file)) !== false)
    {
         if(
    $file != "." && $file != "..")
         {
              if (
    file_exists($destination_file))
              {
                   
    unlink ($destination_file);
              }
              
    copy ($source_file$destination_file);
          }
    }
    closedir($dir); 
    dont know if the open dir is necessary, but that's what i used for doing stuff on the network here at work... the way you're 'doing' things it should work fine.
    Last edited by rweston002; 01-08-04 at 15:30.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •