Jump to content


How to use ftp_chdir() to change into a FULL PATH?

  • Please log in to reply
1 reply to this topic

#1 hstraf

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 12 April 2006 - 06:13 PM

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.

#2 craygo

  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 12 April 2006 - 08:36 PM

You don't need to do anything if you already know where you start when you log in.

If you start in public_html and you want to go to folder "images" which is in public_html you would just use


if you notice there is no forward slash "/" in front of my directory name. By leaving out the forward slash it will change directory relative to the current location or directory.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users