1 | <?php |
||
21 | class FtpService extends ServiceAbstract |
||
22 | { |
||
23 | /** |
||
24 | * The FTP transfer mode. |
||
25 | * |
||
26 | * We set this value = 2, thats the same as the FTP_BINARY constant. |
||
27 | * |
||
28 | * @var int |
||
29 | */ |
||
30 | const TRANSFER_MODE = 2; |
||
31 | |||
32 | /** |
||
33 | * Service connection configuration. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | private $config = array( |
||
38 | 'hostname' => '', |
||
39 | 'port' => 21, |
||
40 | 'timeout' => 90, |
||
41 | 'username' => '', |
||
42 | 'password' => '', |
||
43 | 'debug' => false, |
||
44 | ); |
||
45 | |||
46 | /** |
||
47 | * The FTP connection resource. |
||
48 | * |
||
49 | * @var resource |
||
50 | */ |
||
51 | private $ftp; |
||
52 | |||
53 | /** |
||
54 | * Class constructor. |
||
55 | * |
||
56 | * Create a new service by passing the configuration: |
||
57 | * - hostname : The hostname of the FTP service. |
||
58 | * - port : The FRP port. |
||
59 | * - username : The username to connect to the FTP service. |
||
60 | * - password : The password to connect to the FTP service. |
||
61 | * |
||
62 | * Optional configuration: |
||
63 | * - directory_send : The remote directory to store the request file in. |
||
64 | * - directory_send_processed : The remote directory where the processed |
||
65 | * request files are stored. |
||
66 | * - directory_receive : The remote directory where the translated files are |
||
67 | * stored to be picked up. |
||
68 | * - directory_receive_processed : The repome directory where to put the |
||
69 | * translation files that are successfully processed by the local system. |
||
70 | * |
||
71 | * @param array $config |
||
72 | */ |
||
73 | 81 | public function __construct(array $config) |
|
78 | |||
79 | /** |
||
80 | * @inheritDoc |
||
81 | */ |
||
82 | 18 | public function send(FileInterface $file) |
|
101 | |||
102 | /** |
||
103 | * @inheritDoc |
||
104 | */ |
||
105 | 6 | public function scan() |
|
123 | |||
124 | /** |
||
125 | * @inheritDoc |
||
126 | */ |
||
127 | 9 | public function receive($fileName, $directory) |
|
147 | |||
148 | /** |
||
149 | * @inheritDoc |
||
150 | */ |
||
151 | 9 | public function processed($fileName) |
|
177 | |||
178 | /** |
||
179 | * Get the connection. |
||
180 | * |
||
181 | * @return resource |
||
182 | * A FTP connection resource. |
||
183 | */ |
||
184 | 42 | protected function getConnection() |
|
191 | |||
192 | /** |
||
193 | * Connect to the FTP server. |
||
194 | */ |
||
195 | 42 | protected function connect() |
|
217 | |||
218 | |||
219 | /** |
||
220 | * Write the config to the config array. |
||
221 | * |
||
222 | * @param array $config |
||
223 | */ |
||
224 | 81 | protected function setConfig(array $config) |
|
233 | |||
234 | /** |
||
235 | * Get the hostname from the config. |
||
236 | * |
||
237 | * @return string |
||
238 | */ |
||
239 | 42 | protected function getHostname() |
|
243 | |||
244 | /** |
||
245 | * Get the portnumber from the config. |
||
246 | * |
||
247 | * @return int |
||
248 | */ |
||
249 | 42 | protected function getPort() |
|
253 | |||
254 | /** |
||
255 | * Get the timeout from the config. |
||
256 | * |
||
257 | * @return int |
||
258 | */ |
||
259 | 42 | protected function getTimeout() |
|
263 | |||
264 | /** |
||
265 | * Get the username. |
||
266 | * |
||
267 | * @return string |
||
268 | */ |
||
269 | 78 | protected function getUsername() |
|
273 | |||
274 | /** |
||
275 | * Get the password. |
||
276 | * |
||
277 | * @return string |
||
278 | */ |
||
279 | 78 | protected function getPassword() |
|
283 | |||
284 | /** |
||
285 | * Get debug mode. |
||
286 | * |
||
287 | * @return bool |
||
288 | */ |
||
289 | 18 | protected function isDebug() |
|
293 | } |
||
294 |