1 | <?php |
||
22 | class Ftp extends Xtp |
||
23 | { |
||
24 | use Cleanable; |
||
25 | |||
26 | /** |
||
27 | * FTP connection stream |
||
28 | * |
||
29 | * @var \SebastianFeldmann\Ftp\Client |
||
30 | */ |
||
31 | protected $ftpClient; |
||
32 | |||
33 | /** |
||
34 | * Determine should ftp connects via passive mode. |
||
35 | * |
||
36 | * @var bool |
||
37 | */ |
||
38 | protected $passive; |
||
39 | |||
40 | /** |
||
41 | * Setup the Ftp sync. |
||
42 | * |
||
43 | * @param array $config |
||
44 | * @throws \phpbu\App\Backup\Sync\Exception |
||
45 | * @throws \phpbu\App\Exception |
||
46 | */ |
||
47 | 6 | public function setup(array $config) |
|
48 | { |
||
49 | 6 | $path = Util\Arr::getValue($config, 'path', ''); |
|
50 | 6 | if ('/' === substr($path, 0, 1)) { |
|
51 | 1 | throw new Exception('absolute path is not allowed'); |
|
52 | } |
||
53 | 5 | if (!Util\Arr::isSetAndNotEmptyString($config, 'password')) { |
|
54 | 1 | throw new Exception('option \'password\' is missing'); |
|
55 | } |
||
56 | 4 | parent::setup($config); |
|
57 | |||
58 | 2 | $this->passive = Util\Str::toBoolean(Util\Arr::getValue($config, 'passive', ''), false); |
|
59 | 2 | $this->setUpCleanable($config); |
|
60 | 2 | } |
|
61 | |||
62 | /** |
||
63 | * Check for required loaded libraries or extensions. |
||
64 | * |
||
65 | * @throws \phpbu\App\Backup\Sync\Exception |
||
66 | */ |
||
67 | 4 | protected function checkRequirements() |
|
68 | { |
||
69 | 4 | if (!function_exists('ftp_connect')) { |
|
70 | throw new Exception('ftp functions not enabled'); |
||
71 | } |
||
72 | 4 | } |
|
73 | |||
74 | /** |
||
75 | * Return implemented (*)TP protocol name. |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | 1 | protected function getProtocolName() |
|
80 | { |
||
81 | 1 | return 'FTP'; |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * (non-PHPDoc) |
||
86 | * |
||
87 | * @see \phpbu\App\Backup\Sync::sync() |
||
88 | * @param \phpbu\App\Backup\Target $target |
||
89 | * @param \phpbu\App\Result $result |
||
90 | * @throws \phpbu\App\Backup\Sync\Exception |
||
91 | */ |
||
92 | public function sync(Target $target, Result $result) |
||
108 | |||
109 | /** |
||
110 | * Return FTP client wrapping the ftp connection. |
||
111 | * |
||
112 | * @return \SebastianFeldmann\Ftp\Client |
||
113 | */ |
||
114 | protected function connect() |
||
122 | |||
123 | /** |
||
124 | * Creates collector for FTP |
||
125 | * |
||
126 | * @param \phpbu\App\Backup\Target $target |
||
127 | * @return \phpbu\App\Backup\Collector |
||
128 | */ |
||
129 | protected function createCollector(Target $target): Collector |
||
133 | } |
||
134 |