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 | ); |
||
44 | |||
45 | /** |
||
46 | * The FTP connection resource. |
||
47 | * |
||
48 | * @var resource |
||
49 | */ |
||
50 | private $ftp; |
||
51 | |||
52 | /** |
||
53 | * Class constructor. |
||
54 | * |
||
55 | * Create a new service by passing the configuration: |
||
56 | * - hostname : The hostname of the FTP service. |
||
57 | * - port : The FRP port. |
||
58 | * - username : The username to connect to the FTP service. |
||
59 | * - password : The password to connect to the FTP service. |
||
60 | * |
||
61 | * Optional configuration: |
||
62 | * - directory_send : The remote directory to store the request file in. |
||
63 | * - directory_send_processed : The remote directory where the processed |
||
64 | * request files are stored. |
||
65 | * - directory_receive : The remote directory where the translated files are |
||
66 | * stored to be picked up. |
||
67 | * - directory_receive_processed : The repome directory where to put the |
||
68 | * translation files that are successfully processed by the local system. |
||
69 | * |
||
70 | * @param array $config |
||
71 | */ |
||
72 | 81 | public function __construct(array $config) |
|
77 | |||
78 | /** |
||
79 | * @inheritDoc |
||
80 | */ |
||
81 | 18 | public function send(FileInterface $file) |
|
100 | |||
101 | /** |
||
102 | * @inheritDoc |
||
103 | */ |
||
104 | 6 | public function scan() |
|
122 | |||
123 | /** |
||
124 | * @inheritDoc |
||
125 | */ |
||
126 | 9 | public function receive($fileName, $directory) |
|
146 | |||
147 | /** |
||
148 | * @inheritDoc |
||
149 | */ |
||
150 | 9 | public function processed($fileName) |
|
171 | |||
172 | /** |
||
173 | * Get the connection. |
||
174 | * |
||
175 | * @return resource |
||
176 | * A FTP connection resource. |
||
177 | */ |
||
178 | 42 | protected function getConnection() |
|
185 | |||
186 | /** |
||
187 | * Connect to the FTP server. |
||
188 | */ |
||
189 | 42 | protected function connect() |
|
211 | |||
212 | |||
213 | /** |
||
214 | * Write the config to the config array. |
||
215 | * |
||
216 | * @param array $config |
||
217 | */ |
||
218 | 81 | protected function setConfig(array $config) |
|
227 | |||
228 | /** |
||
229 | * Get the hostname from the config. |
||
230 | * |
||
231 | * @return string |
||
232 | */ |
||
233 | 42 | protected function getHostname() |
|
237 | |||
238 | /** |
||
239 | * Get the portnumber from the config. |
||
240 | * |
||
241 | * @return int |
||
242 | */ |
||
243 | 42 | protected function getPort() |
|
247 | |||
248 | /** |
||
249 | * Get the timeout from the config. |
||
250 | * |
||
251 | * @return int |
||
252 | */ |
||
253 | 42 | protected function getTimeout() |
|
257 | |||
258 | /** |
||
259 | * Get the username. |
||
260 | * |
||
261 | * @return string |
||
262 | */ |
||
263 | 78 | protected function getUsername() |
|
267 | |||
268 | /** |
||
269 | * Get the password. |
||
270 | * |
||
271 | * @return string |
||
272 | */ |
||
273 | 78 | protected function getPassword() |
|
277 | } |
||
278 |