I am trying to write a simple script that will recursively copy all files from the script folder into an FTP target folder.

The problem is that I only know what is the FULL filepath to where the files should go. But the ftp_chdir() function won't work with this full path. It needs a path that is "relative" to the current ftp location after logging in.

For example:

I have the full path: /home/username/public_html/path/to/my/files/
I need the relative path to their ftp root: public_html/path/to/my/files/

Is there any way for my script to somehow figure out what is the "relative to the ftp login root" for where the new folder should be located... based on the full file path?

I have no idea beforehand what kind of server they'll be using.

    if you already know the exact absolute path then is it necessary to use [man]ftp_chdir[/man]? can't you feed that full path to [man]ftp_put[/man]?

      devinemke wrote:

      if you already know the exact absolute path then is it necessary to use [man]ftp_chdir[/man]? can't you feed that full path to [man]ftp_put[/man]?

      The ftp_put() function doesn't seem to accept a full path. :mad:

        ok then, if you know that the directory structure will always look like that then you could do:

        $path = '/home/username/public_html/path/to/my/files/';
        $realtive_path = stristr($path, '/public_html');
        
          devinemke wrote:

          ok then, if you know that the directory structure will always look like that then you could do:

          $path = '/home/username/public_html/path/to/my/files/';
          $realtive_path = stristr($path, '/public_html');
          

          I won't know if "/public_html" is their web root. The example I gave in my post was just an example.

          In fact, they could have a web root like this:

          /path/to/some/funky/web/root/here/

          The only thing I will "know" with any certainty are the PHP global server values, and the path to wherever my script is running.

            Write a Reply...