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!