4
从远程服务器获取ftp文件列表的最佳做法是什么?PHP - 从远程服务器获取ftp列表的最佳做法是什么?
1)使用FTP_CONNECT()函数
<?php
// set up connection
$conn = ftp_connect($ftp_server);
// login with username and password
$login = ftp_login($conn, $ftp_user_name, $ftp_user_pass);
// get contents of the current directory
$content = ftp_nlist($conn, ".");
// output content
var_dump($content);
?>
或
2)使用SCANDIR(),然后输出文件列表与的print_r()
<?php
$path = "ftp://login:[email protected]";
$files = scandir($path);
print_r($files);
?>
两种方法都输出一个带有ftp目录/文件的数组。
你可以按照第一种方法,因为这方法 是安全的连接到FTP和扫描 – Prasad