Getting a list of files and folders from a remote server in 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); 

... 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 at the url:

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

How to find file and folder names from example.com ?

+6
source share
5 answers

It is possible. You just need 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; } } ?> 
+8
source

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

+6
source

Of course, this is impossible, otherwise the sites will be much more vulnerable, since everyone can study their catalog directories!

If you have another way to access this website (for example, if it is yours), for example FTP or SSH, this becomes possible.

+4
source

Perhaps with php it is impossible .. but there are r programs that can do what you are trying to do. "intellitamper" is one of them. http://www.softpedia.com/get/Internet/Other-Internet-Related/IntelliTamper.shtml <- link.

  • its not working on windows 7
  • u cannot get server side files like php.
  • u can only see folders, html, js or image files.

Otherwise, it would be paradise ... anyone could hack into any site.

0
source

This should work fine on 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>'; } 
0
source

Source: https://habr.com/ru/post/901721/


All Articles