如何使用本地主机中的 php 文件计算远程主机文件夹中的文件数


How to count number of files in a folder in a remote host with a php file in localhost?

我想计算远程主机文件夹中的文件数。路径是可遍历的。我要检查的文件是在本地主机中?
怎么做?
我找不到使用 glob 函数在远程主机中获取文件的示例。可能吗?

不能在远程主机上执行代码。更好的解决方案是放置一个脚本,用于计算文件数量并在远程主机上回显数字,然后执行以下操作:

$num_files = file_get_contents('http://remoteaddr/count_files.php');

你要么需要在远程机器上有一个php文件,要么你必须研究PHP的ftp功能。

function count_files($user, $host, $dir_path) {
    $command = "ssh {$user}@{$host} ls -l {$dir_path} | wc -l";
    $res = (int)system($command);
    return $res - 1;
}