Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting File and Folder List from Remote Server in PHP

Tags:

php

When I run:

$url='foldername';
$dir = opendir($url);

//List files in images directory
while (($file = readdir($dir)) !== false)
  {

  echo "filename: " . $file . "<br />";
  }
closedir($dir); 

...it outputs:

filename: a.gif 
filename: file.html
filename: g.gif
filename: gg.html

I would like to see all the files and folders on another server from the URL:

$url="http ://example.com"

How do I find the files and folder names from example.com?

like image 387
vineeth Avatar asked Nov 17 '11 15:11

vineeth


3 Answers

It is possible. Just got to go outside the box. Only flaw with this is index output

<?
    $matches = array();
    preg_match_all("/(a href\=\")([^\?\"]*)(\")/i", get_text('http://www.website.com/ images/'), $matches);
    foreach($matches[2] as $match)
    {
        echo $match . '<br>';
    }

    function get_text($filename)
    {
        $fp_load = fopen("$filename", "rb");
        if ( $fp_load )
        {
            while ( !feof($fp_load) )
            {
                $content .= fgets($fp_load, 8192);
            }
            fclose($fp_load);
        return $content;
        }
    }
?>
like image 89
shnackhag Avatar answered Nov 04 '22 06:11

shnackhag


http:// does not support directory listing. What you're trying to do is impossible.

like image 31
Tim Cooper Avatar answered Nov 04 '22 07:11

Tim Cooper


It's impossible of course, otherwise websites would be much more vulnerable since anyone could explore their directories tree!

If you have another way of accessing that website (e.g. if it's yours), like FTP or SSH, it becomes possible.

like image 4
antoine129 Avatar answered Nov 04 '22 05:11

antoine129