get_ftp_list(); // read list * print_r($ftp_files); // easy example to output list * ********************************************************************** * */ class ftp { var $_ftp_data = array(); // server and login var $_conn_id = ""; // connection id var $_ftp_possible = false; // ftp possible var $_ftp_ok = false; // ftp login ok var $_ftp_list = array(); // ftp list of all directories and files incl. filesize /** * CONTRUCTOR */ function ftp($ftpdata) { $this->_ftp_data = $ftpdata; $this->_if_ftp_possible(); $this->_connect_to_ftp(); } /** * PRIVATE - Teste ob überhaupt ein Connect auf Port 21 möglich ist. */ function _if_ftp_possible() { if($fp = @fsockopen ($this->_ftp_data["server"], 21, $errno, $errstr, 3)) { fclose($fp); $this->_ftp_possible = true; } else { $this->_ftp_possible = false; } } /** * PRIVATE - Connect to FTP */ function _connect_to_ftp() { if ($this->_ftp_possible) { $this->_conn_id = ftp_connect($this->_ftp_data["server"]); $conn_ok = @ftp_login($this->_conn_id, $this->_ftp_data["user"], $this->_ftp_data["pass"]); $this->_ftp_ok = ($conn_ok) ? true : false; } } /** * PRIVATE - Read the files */ function _get_dirs_files ($path="/") { if ($this->_ftp_ok) { if ($contents = ftp_rawlist($this->_conn_id, $path)) { foreach( $contents as $key => $filedir) { $item = split("[ ]+",$contents[$key],9); if(ereg("^d(.*)",$item[0])) $this->_get_dirs_files($path.$item[8]."/"); else $this->_ftp_list[$path][] = array("name" => $item[8], "size" => $item[4]); } // foreach } // if contents else { $this->_ftp_list[$path] = "no files found"; } } // if ok } // get_dirs_files /** * Return a list of ftp directories and files */ function get_ftp_list($path="/") { if ($this->_ftp_ok) { $this->_ftp_list = array(); // remove possible old data $this->_get_dirs_files($path); return $this->_ftp_list; } return false; } } // class /**************************************************************/ ?>