public function listFilesRaw(string $dir = ".", int $attempts = 5, int $sleepBetweenAttempts = 5)
    {
        $total = @ftp_rawlist($this->ftp, $dir);

        if ($total === false) {
            // Check if tries left call method again
            if (--$attempts > 0) {
                sleep($sleepBetweenAttempts);

                return $this->listFilesRaw($dir, $attempts, $sleepBetweenAttempts);
            }

            throw new Exception(sprintf("Cannot list files in %s", $dir));
        }

        $columnMap = [
            "permissions",
            "number",
            "owner",
            "group",
            "size",
            "month",
            "day",
            "year",
            "name",
        ];

        $monthMap = [
            'Jan'  => '01',
            'Feb'  => '02',
            'Mar'  => '03',
            'Apr'  => '04',
            'May'  => '05',
            'Jun'  => '06',
            'Jul'  => '07',
            'Aug'  => '08',
            'Sep'  => '09',
            'Sept' => '09',
            'Oct'  => '10',
            'Nov'  => '11',
            'Dec'  => '12',
        ];

        $files = [];
        foreach ($total as $rawString) {
            $data    = [];
            $rawList = preg_split("/\s*/", $rawString, -1, PREG_SPLIT_NO_EMPTY);

            foreach ($rawList as $col => $value) {
                if ($col > 8) { // Filename with spaces
                    $data[$columnMap[8]] .= " " . $value;
                    continue;
                }
                $data[$columnMap[$col]] = $value;
            }

            $data['month'] = $monthMap[$data['month']];
            $data['time']  = "00:00";

            if (strpos($data['year'], ':') !== false) {
                $data['time'] = $data['year'];
                if ((int) $data['month'] > (int) date('m')) {
                    $data['year'] = date('Y', time() - 60 * 60 * 24 * 365);
                } else {
                    $data['year'] = date('Y');
                }
            }

            $files[] = $data;
        }

        return $files;
    }
public function listFilesRaw(string $dir = ".", int $attempts = 5, int $sleepBetweenAttempts = 5)
    {
        $total = @ftp_rawlist($this->ftp, $dir);

        if ($total === false) {
            // Check if tries left call method again
            if (--$attempts > 0) {
                sleep($sleepBetweenAttempts);

                return $this->listFilesRaw($dir, $attempts, $sleepBetweenAttempts);
            }

            throw new Exception(sprintf("Cannot list files in %s", $dir));
        }

        $columnMap = [
            "permissions",
            "number",
            "owner",
            "group",
            "size",
            "month",
            "day",
            "year",
            "name",
        ];

        $monthMap = [
            'Jan'  => '01',
            'Feb'  => '02',
            'Mar'  => '03',
            'Apr'  => '04',
            'May'  => '05',
            'Jun'  => '06',
            'Jul'  => '07',
            'Aug'  => '08',
            'Sep'  => '09',
            'Sept' => '09',
            'Oct'  => '10',
            'Nov'  => '11',
            'Dec'  => '12',
        ];

        $files = [];
        foreach ($total as $rawString) {
            $data    = [];
            $rawList = preg_split("/\s*/", $rawString, -1, PREG_SPLIT_NO_EMPTY);

            foreach ($rawList as $col => $value) {
                if ($col > 8) { // Filename with spaces
                    $data[$columnMap[8]] .= " " . $value;
                    continue;
                }
                $data[$columnMap[$col]] = $value;
            }

            $data['month'] = $monthMap[$data['month']];
            $data['time']  = "00:00";

            if (strpos($data['year'], ':') !== false) {
                $data['time'] = $data['year'];
                if ((int) $data['month'] > (int) date('m')) {
                    $data['year'] = date('Y', time() - 60 * 60 * 24 * 365);
                } else {
                    $data['year'] = date('Y');
                }
            }

            $files[] = $data;
        }

        return $files;
    }
public function listFilesRaw ( string $ dir = "." , int $ attempts = 5 , int $ sleepBetweenAttempts = 5 ) { $ total = @ ftp_rawlist ( $ this -> ftp , $ dir ) ; if ( $ total === false ) { // Check if tries left call method again if ( -- $ attempts > 0 ) { sleep ( $ sleepBetweenAttempts ) ; return $ this -> listFilesRaw ( $ dir , $ attempts , $ sleepBetweenAttempts ) ; } throw new Exception ( sprintf ( "Cannot list files in %s" , $ dir ) ) ; } $ columnMap = [ "permissions" , "number" , "owner" , "group" , "size" , "month" , "day" , "year" , "name" , ] ; $ monthMap = [ 'Jan' => '01' , 'Feb' => '02' , 'Mar' => '03' , 'Apr' => '04' , 'May' => '05' , 'Jun' => '06' , 'Jul' => '07' , 'Aug' => '08' , 'Sep' => '09' , 'Sept' => '09' , 'Oct' => '10' , 'Nov' => '11' , 'Dec' => '12' , ] ; $ files = [ ] ; foreach ( $ total as $ rawString ) { $ data = [ ] ; $ rawList = preg_split ( "/\s*/" , $ rawString , - 1 , PREG_SPLIT_NO_EMPTY ) ; foreach ( $ rawList as $ col => $ value ) { if ( $ col > 8 ) { // Filename with spaces $ data [ $ columnMap [ 8 ] ] .= " " . $ value ; continue ; } $ data [ $ columnMap [ $ col ] ] = $ value ; } $ data [ 'month' ] = $ monthMap [ $ data [ 'month' ] ] ; $ data [ 'time' ] = "00:00" ; if ( strpos ( $ data [ 'year' ] , ':' ) !== false ) { $ data [ 'time' ] = $ data [ 'year' ] ; if ( ( int ) $ data [ 'month' ] > ( int ) date ( 'm' ) ) { $ data [ 'year' ] = date ( 'Y' , time ( ) - 60 * 60 * 24 * 365 ) ; } else { $ data [ 'year' ] = date ( 'Y' ) ; } } $ files [ ] = $ data ; } return $ files ; }
Get raw data of files in directory on ftp-server.

@param string $dir                  [optional] Directory to search in.
@param int    $attempts             [optional] Number of retries in case of error.
@param int    $sleepBetweenAttempts [optional] Sleep time in seconds between attempts.

@return array
@throws Exception
Get raw data of files in directory on ftp - server .