ftp_nlist() some servers add slashes to folder/file names, some don't why? and fix?

Hi,

A question for you guys.

I am connecting to an FTP server through php. Using ftp_nlist() I get a list of folders and files from the current directory and depending on the server I get a different style of naming back.

On my laptop I am running the FTP server that came with Xampp (filezilla) and it shows me folder/file names (from now folder names) like so (I don’t get the full tree straight away, but I wrote it down to illustrate the different levels):

/app
/app/controllers
/app/index.php
/cake
/etc
/index.php

On my desktop I use the same code but I connect to a different host, namely my hosting provider, which runs some linux web server and I get this for the same folders and files:

app
controllers
index.php
cake
etc
index.php

I depend quite a bit on the way the names are shown and I want to know why the nlist is different.

Of course a solution could be that I check if there is a ‘/’ in the name and then explode on it and then use the highest key value. But I want to force one of both ways onto the connection.

Why and how?

That should have been:


/app
  /app/controllers
  /app/index.php
/cake
  /etc
/index.php


app
  controllers
  index.php
cake
  etc
index.php