Автор: Nick Sagona, III (dev@nolainteractive.com)
Пример #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();
     }
 }
Пример #2
0
<?php

require_once '../../bootstrap.php';
use Pop\Ftp\Ftp;
try {
    $ftp = new Ftp('ftp.yourserver.com', 'username', 'password');
    $ftp->pasv(true)->chdir('./httpdocs/')->put('test.pdf', '../assets/files/test.pdf', FTP_BINARY);
    echo 'File Sent!';
} catch (\Exception $e) {
    echo $e->getMessage();
}