Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP脚本不会从FTP返回所有.PHP文件_Php_Ftp - Fatal编程技术网

PHP脚本不会从FTP返回所有.PHP文件

PHP脚本不会从FTP返回所有.PHP文件,php,ftp,Php,Ftp,我正在使用以下脚本连接到FTP服务器 脚本可以很好地连接到FTP服务器,但是没有返回任何具有PHP扩展名的文件,它是空的。不确定问题出在哪里。理想情况下,它应该显示所有后缀为.php的文件 我试图将路径$startdir更改为/test或仅test,但它显示为空白 Ftp文件夹结构为 下面的PHP代码 <?php error_reporting( E_ALL ); ini_set( "display_errors", 1 ); $hostname = "ftp.abc.com"; $u

我正在使用以下脚本连接到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;
    }

?>


我刚在我的ftp服务器上试用过,效果很好,我在
$files
中得到了我的列表,它在我的服务器上显示为空。我刚在我的ftp服务器上试用过,效果很好,我在
$files
中得到了我的列表,它在我的服务器上显示为空