Determine between files and folders using cURL

curl, ftp, php

Solution

-rw-r--r--   1 user group         24 Apr 25  2009 robots.txt
drwxr-xr-x   2 user group       4096 Feb 21  2009 sample

I found out myself, the 1st character of the permission string dictates whether it is a directory or not.

Problem

I'm writing a script to download files from an FTP server using cURL + PHP, at the moment I am just trying to build a complete file structure, here's the code I'm using so far: ``` <?php $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "ftp://www.example.com"); curl_setopt($curl, CURLOPT_USERPWD, "user:pwd"); curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1) ; curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'NLST'); // or curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'LIST -a'); $ftp=curl_exec($curl); $directory=split("[\n|\r]",$ftp); echo("<pre>".print_r($directory,true)."</pre>"); foreach($directory as $key=>$value) if($value=='') unset($directory[$key]); echo("<pre>".print_r($directory,true)."</pre>"); curl_close ($curl); ?> ``` I can use either `NLST` or the `LIST` function, but what I want to do is programatically determine what are files and what are folders. Thanks!

Original source