Jump to content

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


hstraf

Recommended Posts

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 [b]ftp_chdir()[/b] function won't work with this full path. It needs a path that is "[i]relative[/i]" to the current ftp location after logging in.

For example:

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

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.
Link to comment
Share on other sites

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

images/filename.jpg

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.

Ray
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.