我使用以下脚本连接到FTP服务器。
脚本连接到FTP服务器,但没有返回任何具有PHP扩展名的文件,它是空白的。不确定是什么问题。理想情况下,它应该显示所有带有后缀.php。
的文件我尝试将路径$ startdir更改为/test
或仅test
,但它显示为空白。
Ftp文件夹结构
以下的PHP代码
<?php
error_reporting( E_ALL );
ini_set( "display_errors", 1 );
$hostname = "ftp.abc.com";
$username = "dev28@sbc.com";
$password="wsedr";
echo $_SERVER['DOCUMENT_ROOT'];
$startdir = '/home/public_html/dev21/test'; // absolute path
$suffix = "php"; // suffixes to list
$files = array();
$conn_id = ftp_connect($hostname);
$login = ftp_login($conn_id, $username, $password);
if (!$conn_id) {
echo 'Wrong server!';
exit;
} else if (!$login) {
echo 'Wrong username/password!';
exit;
} else {
$files = raw_list("$startdir");
}
ftp_close($conn_id);
function raw_list($folder) {
global $conn_id;
global $suffix;
global $files;
$suffixes = explode(",", $suffix);
$list = ftp_rawlist($conn_id, $folder);
$anzlist = count($list);
$i = 0;
while ($i < $anzlist) {
$split = preg_split("/[\s]+/", $list[$i], 9, PREG_SPLIT_NO_EMPTY);
$itemname = $split[8];
$endung = strtolower(substr(strrchr($itemname ,"."),1));
$path = "$folder/$itemname";
if (substr($list[$i],0,1) === "d" AND substr($itemname,0,1) != ".") {
raw_list($path);
} else if(substr($itemname,0,2) != "._" AND in_array($endung,$suffixes)) {
array_push($files, $path);
}
$i++;
}
return $files;
}
?>