PHP – FTP-Verbindung wird unterbrochenPhp

PHP-Programmierer chatten hier
Anonymous
 PHP – FTP-Verbindung wird unterbrochen

Post by Anonymous »

Ich versuche, eine PHP-Klasse für eine rekursive Verzeichnisliste zu erstellen. Es ist eine einfache Klasse, aber aus irgendeinem Grund verliere ich anscheinend die Verbindung (Oder der Fehler liegt irgendwo anders, aber ich finde ihn nicht.
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();
Aber dieser Aufruf löst den Fehler aus:

Code: Select all

$ftp = new FTP($server);
$files = $ftp->get_fiels_recursive($path, 1);
var_dump($files);
exit();
Vielleicht mache ich etwas falsch (es muss sein), aber ich finde es nicht.
Vielleicht hat jemand einen Tipp für mich.
Danke!

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post