dongwen1871 2010-03-18 22:47
浏览 41
已采纳

使用cURL确定文件和文件夹之间的距离

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("[
|]",$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!

  • 写回答

1条回答 默认 最新

  • doulan9419 2010-03-19 20:51
    关注
    -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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?