AAA Главная
Примеры PHP Примеры JavaScript Примеры Ajax Примеры CSS,HTML

Список файлов через FTP

Задача: вывести список всех флеш роликов(swf) лежащих на FTP.

error_reporting(E_ALL | E_STRICT);

class FtpSearch {
    var $server_url = '';
    var $username = '';
    var $password = '';
    var $remote_folder = '';
    var $ftp;

    function log($message){
        print $message;
    }

    function show(){
        $this- = ftp_connect($this->server_url);
        if ($this->ftp===FALSE){
            $this->log('Can not connect to FTP server');
        }
        else {
            $this->log('Connected successful');
            if(ftp_login($this->ftp,$this->username,$this->password)){
                $this->getListOfFiles($this->remote_folder,$this->remote_folder);
            }
            else {
                $this->log('Login failure!');
            }
            ftp_quit($this->ftp);
            $this->log('Connection closed!');
        }
    }

    function getListOfFiles($folder,$filename){
        flush ();
        set_time_limit(30);
        if (preg_match('/\.swf$/',$folder)){
            print $folder.'<br />';
        }
        $c = @ftp_chdir($this->ftp,$filename);
        if ($c){
            $list = ftp_rawlist($this->ftp,'');
            $files = [];
            reset($list);
            while (list(,$row) = each($list)) {
                $buf="";
                if ($row[0]=='d'||$row[0]=='-'){
                    $buf = ltrim(substr($row,55));
                    $files[]=$buf;
                }
            }
            if ($files!==FALSE){
                foreach($files as $file){
                    if (($file!='..') and ($file!='.')){
                        $this->getListOfFiles($folder.'/'.$file,$file);
                    }
                }
            }
            $c = ftp_chdir($this->ftp,'..');
        }
    }
}
$c = new FtpSearch();
$c->show();

.

© Copyright 2008- by KDG



Rambler's Top100