从远程服务器的PHP目录列表 [英] PHP directory list from remote server

查看:136
本文介绍了从远程服务器的PHP目录列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用opendir函数来读取远程服务器知道其IP地址的目录列表?

How can i use opendir function to read the directory list of a remote server knowing its IP address?

推荐答案

假设你正在尝试使用HTTP访问远程服务器,您将无法直接执行此操作。由于HTTP真正访问远程服务器的Web服务,因此它控制文件如何呈现给您。在许多Web服务器的情况下,您可以打开文件夹内容的索引。这将使文件夹中的条目以HTML形式显示在浏览器中。为了遍历目录结构,您需要解析此HTML以查找路径信息。

Assuming you are trying to access the remote server using HTTP, you won't be able to do this directly. Since HTTP is really going access the web service of your remote server, it controls how the files are presented to you. In the case of many web servers, you can turn on "indexes" for folder contents. This causes the entries in the folder to be displayed in your browser as HTML. In order to traverse the directory structure, you would need to parse this HTML to find the path information.

如果使用FTP,可以传递 ftp:// ... URL到 opendir()版本5.0。请注意,您的服务器管理员可以关闭此功能。如果您无法直接使用此功能,请参阅 FTP功能 PHP手册(包括 ftp_nlist() 列出文件)

If you are using FTP, you can pass the ftp://... URL to opendir() as of version 5.0. Note that this capability can be turned off by your server admin. If you cannot use this feature directly, see the FTP functions manual for PHP (including ftp_nlist() for listing files).

以上参考文献中的一个例子:

An example from the above references:

<?php

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// get contents of the current directory
$contents = ftp_nlist($conn_id, ".");

// output $contents
var_dump($contents);

?>

这篇关于从远程服务器的PHP目录列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆