Home » Php » Getting File and Folder List from Remote Server in PHP

Getting File and Folder List from Remote Server in PHP

Posted by: admin July 12, 2020 Leave a comment

Questions:

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?

How to&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;
        }
    }
?>

Answer:

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

Answer:

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.

Answer:

Maybe with php is impossible.. but there r programs that can do what u r trying to do.
“intellitamper” is one of them. http://www.softpedia.com/get/Internet/Other-Internet-Related/IntelliTamper.shtml <– the link.

  • its doesnt work on windows 7
  • u cannot get server sides files like php.
  • u can only see folders, html, js or image files.

Otherwise it would be heaven… anyone could hack any website.

Answer:

This should work fine in some servers

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;

    }
}


$matches = array();

preg_match_all("/(a href\=\")([^\?\"]*)(\")/i", get_text('https://www.example.com/'), $matches);

foreach($matches[2] as $match) {
    echo $match . '<br>';
}