Загрузить весь каталог через PHP FTP

Итак, я взял код @ iYETER php-oop и обернул его как объект php5 класса.

Вы можете вызвать dir этот код следующими строками:

$ftp = new FtpNew("hostname");

$ftpSession = $ftp->login("username", "password");

if (!$ftpSession) die("Failed to connect.");

$errorList = $ftp->send_recursive_directory("/local/dir/", "/remote/dir/");
print_r($errorList);

$ftp->disconnect();

Он folders рекурсивно сканирует локальный php-frameworks каталог и помещает его в php-errors удаленный относительный каталог. Если upload он обнаруживает какие-либо php-include ошибки, он создает иерархию php массивов для каждого файла php-fpm и их кода исключения (пока ftp я захватил только 2, если uploads это другая ошибка, он выбрасывает php.ini маршрут по умолчанию на данный php-mail момент)

Класс, в который он php-frameworks заключен:

connectionID = ftp_connect($ftpHost);
}

public function __destruct() {
    $this->disconnect();
}

public function connect($ftpHost) {     
    $this->disconnect();
    $this->connectionID = ftp_connect($ftpHost);
    return $this->connectionID;
}

public function login($ftpUser, $ftpPass) {
    if (!$this->connectionID) throw new Exception("Connection not established.", -1);
    $this->ftpSession = ftp_login($this->connectionID, $ftpUser, $ftpPass);
    return $this->ftpSession;
}

public function disconnect() {
    if (isset($this->connectionID)) {
        ftp_close($this->connectionID);
        unset($this->connectionID);
    }
}

public function send_recursive_directory($localPath, $remotePath) {
    return $this->recurse_directory($localPath, $localPath, $remotePath);
}

private function recurse_directory($rootPath, $localPath, $remotePath) {
    $errorList = array();
    if (!is_dir($localPath)) throw new Exception("Invalid directory: $localPath");
    chdir($localPath);
    $directory = opendir(".");
    while ($file = readdir($directory)) {
        if (in_array($file, $this->blackList)) continue;
        if (is_dir($file)) {
            $errorList["$remotePath/$file"] = $this->make_directory("$remotePath/$file");
            $errorList[] = $this->recurse_directory($rootPath, "$localPath/$file", "$remotePath/$file");
            chdir($localPath);
        } else {
            $errorList["$remotePath/$file"] = $this->put_file("$localPath/$file", "$remotePath/$file");
        }
    }
    return $errorList;
}

public function make_directory($remotePath) {
    $error = "";
    try {
        ftp_mkdir($this->connectionID, $remotePath);
    } catch (Exception $e) {
        if ($e->getCode() == 2) $error = $e->getMessage(); 
    }
    return $error;
}

public function put_file($localPath, $remotePath) {
    $error = "";
    try {
        ftp_put($this->connectionID, $remotePath, $localPath, FTP_BINARY); 
    } catch (Exception $e) {
        if ($e->getCode() == 2) $error = $e->getMessage(); 
    }
    return $error;
}
}

php

upload

ftp

directory

2022-09-06T08:00:56+00:00
Вопросы с похожей тематикой, как у вопроса:

Загрузить весь каталог через PHP FTP