Determine between files and folders using cURL

Posted by ILMV on Stack Overflow See other posts from Stack Overflow or by ILMV
Published on 2010-03-18T22:47:15Z Indexed on 2010/03/18 22:51 UTC
Read the original article Hit count: 415

Filed under:
|
|

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!

© Stack Overflow or respective owner

Related posts about curl

Related posts about ftp