Pop\Ftp\Ftp::put PHP Метод

put() публичный Метод

Put file.
public put ( string $remote, string $local, integer | string $mode = FTP_BINARY ) : Ftp
$remote string
$local string
$mode integer | string
Результат Ftp
    public function put($remote, $local, $mode = FTP_BINARY)
    {
        if (!ftp_put($this->conn, $remote, $local, $mode)) {
            throw new Exception('Error: There was an error putting the file ' . $local);
        }
    }

Usage Example

Пример #1
0
 public function fetch($resource)
 {
     if ($this->isValidPostData($this->request->getPost())) {
         $data = $this->parsePostData();
         try {
             $ftp = new Ftp($data['address'], $data['username'], $data['password'], $data['ssl']);
             $ftp->pasv($data['pasv']);
             switch ($resource) {
                 case 'phirecms':
                     if (file_exists(__DIR__ . '/../../public/releases/phire/phire.json')) {
                         $files = json_decode(file_get_contents(__DIR__ . '/../../public/releases/phire/phire.json'), true);
                         $remote = $data['root'] . $data['base_path'] . $data['app_path'] . '/';
                         foreach ($files as $file) {
                             $dir = dirname($file);
                             if (!$ftp->dirExists($remote . $dir)) {
                                 $ftp->mkdirs($remote . $dir);
                             }
                             $ftp->put($remote . $file, __DIR__ . '/../../public/releases/phire/phire-cms/' . $file);
                         }
                     }
                     break;
                 default:
                     if ($this->request->getQuery('theme') == 1 && file_exists(__DIR__ . '/../../public/releases/themes/' . $resource . '.zip') && !empty($data['content_path'])) {
                         $remote = $data['root'] . $data['base_path'] . $data['content_path'] . '/themes/';
                         $ftp->put($remote . $resource . '.zip', __DIR__ . '/../../public/releases/themes/' . $resource . '.zip');
                         $ftp->chmod($resource . '.zip', 0777);
                     } else {
                         if (file_exists(__DIR__ . '/../../public/releases/modules/' . $resource . '.zip') && !empty($data['content_path'])) {
                             $remote = $data['root'] . $data['base_path'] . $data['content_path'] . '/modules/';
                             $ftp->put($remote . $resource . '.zip', __DIR__ . '/../../public/releases/modules/' . $resource . '.zip');
                             $ftp->chmod($resource . '.zip', 0777);
                         }
                     }
             }
             $this->response->setBody(json_encode(['message' => 'Successful transfer.'], JSON_PRETTY_PRINT));
             $this->response->send(200);
         } catch (\Exception $e) {
             $this->response->setBody(json_encode(['error' => $e->getMessage()], JSON_PRETTY_PRINT));
             $this->response->send(401);
         }
     } else {
         $this->error();
     }
 }