Sarath
Sarath

Reputation: 9156

Access dir from remote server in php?

Is it possible to list all the files from a remote server.I am running this code in serverOne.com , its a php server .I want to access serverTwo.com/dirOne its aTomcat server.

$path = "http://www.serverTwo.com/dirOne";

if ($handle = opendir($widget_path)) {
    while (false !== ($widgetfile = readdir($handle))) 
                         {
                if ($widgetfile != "." && $widgetfile != "..")
                                 {  
                   echo $widgetfile;     
                }
            }
            closedir($handle);
}

Upvotes: 1

Views: 307

Answers (3)

ben
ben

Reputation: 1936

You can probably connect to your second server using FTP

Upvotes: 1

Marc B
Marc B

Reputation: 360862

If the other server has directory browsing enabled and there's no default document in the directory, then generally you get an HTML page containing a file listing. But if it's disabled and/or default-documented, then no, you can't. Not directly.

Upvotes: 1

Mike Dinescu
Mike Dinescu

Reputation: 55760

The short answer is No. Definitely not like that because that would be a serious security problem, don't you think?!

There are ways you could establish a link between two servers but just allowing pretty much anyone to list files and read files off of one server from another would be quite bad.

Upvotes: 2

Related Questions