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