Die Klasse:
Code: Select all
class FTP {
private $connection, $server, $files;
function __construct($server) {
$this->server = $server;
$this->connect();
}
private function connect() {
$this->connection = ftp_connect(
$this->server->host,
$this->server->port
);
ftp_login($this->connection,
$this->server->username,
$this->server->password
);
ftp_chdir($this->connection, $this->server->working_directory);
return $this;
}
public function get_files($path = ".") {
return ftp_nlist($this->connection, $path);
}
public function get_fiels_recursive($path = ".", $max_level = 0) {
$this->files = [];
return $this->get_remote_files($path, $max_level);
}
private function get_remote_files($path = ".", $max_level = 0, $level = 0) {
$remote_files = ftp_nlist($this->connection, $path);
foreach ($remote_files as $remote_file) {
$remote_path = $path . basename($remote_file) . "/";
if (($level is_dir($remote_path)) {
$this->get_remote_files($remote_path, $level++, $max_level);
} else {
array_push($this->files, $remote_file);
}
}
return $this->files;
}
private function is_dir($path) {
$path = trim($path, '/');
$path = '/' . $path;
if ($path === '/') {
return true;
}
var_dump($this->connection, $path);
$haystack = ftp_nlist($this->connection, $path); // get_files($path);
var_dump($names);
exit();
Code: Select all
$ftp = new FTP($server);
$files = $ftp->get_fiels_recursive($path, 1);
var_dump($files);
exit();
Vielleicht hat jemand einen Tipp für mich.
Danke!
Mobile version