我通过php的ftp连接连接到另一台服务器。通过php ftp远程递归搜索目录
不过,我需要能够提取所有HTML文件从它的Web根目录,这是造成我有点头疼......
我发现这个职位Recursive File Search (PHP)其中谈到使用RecursiveDirectoryIterator
功能然而,这是与自己的php脚本位于同一服务器上的目录。
我已经受够了写我自己的功能,但不知道我有去是正确的......假设发送到方法的原始路径是服务器的文档根:
public function ftp_dir_loop($path){
$ftpContents = ftp_nlist($this->ftp_connection, $path);
//loop through the ftpContents
for($i=0 ; $i < count($ftpContents) ; ++$i)
{
$path_parts = pathinfo($ftpContents[$i]);
if(in_array($path_parts['extension'], $this->accepted_file_types){
//call the cms finder on this file
$this->html_file_paths[] = $path.'/'.$ftpContents[$i];
} elseif(empty($path_parts['extension'])) {
//run the directory method
$this->ftp_dir_loop($path.'/'.$ftpContents[$i]);
}
}
}
}
有没有人看过预制课程来做类似的事情?
这应该这样做,虽然NLIST()返回false像路径错误,无法找到或者是一个文件,你应该检查这一点。 –
顺便说一句,也许更可靠的方法来检测目录是通过使用“-al $路径”作为第二个参数到ftp_nlist()。 –