1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | /** |
||
5 | * Gateway Client Class |
||
6 | * @category Ticaje |
||
7 | * @package Ticaje_Connector |
||
8 | * @author Hector Luis Barrientos <[email protected]> |
||
9 | */ |
||
10 | |||
11 | namespace Ticaje\Connector\Gateway\Client; |
||
12 | |||
13 | use Ticaje\Connector\Interfaces\CredentialInterface; |
||
14 | use Ticaje\Connector\Interfaces\Protocol\FtpClientInterface; |
||
15 | |||
16 | /** |
||
17 | * Class Ftp |
||
18 | * @package Ticaje\Connector\Gateway\Client |
||
19 | */ |
||
20 | class Ftp extends Base implements FtpClientInterface |
||
21 | { |
||
22 | private $connected; |
||
23 | |||
24 | /** |
||
25 | * @inheritDoc |
||
26 | */ |
||
27 | public function isConnected(): bool |
||
28 | { |
||
29 | return $this->connected; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @inheritDoc |
||
34 | */ |
||
35 | public function connect(CredentialInterface $credentials) |
||
36 | { |
||
37 | try { |
||
38 | $this->client = $this->clientFactory->create($credentials->getAll()); |
||
39 | $this->connected = $this->client->login($credentials->username, $credentials->password) ? true : false; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
40 | } catch (\Exception $exception) { |
||
41 | $this->connected = false; |
||
42 | } |
||
43 | return $this->connected; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @inheritDoc |
||
48 | */ |
||
49 | public function get($path = '') |
||
50 | { |
||
51 | return $this->client->get($path); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @inheritDoc |
||
56 | */ |
||
57 | public function ls($dir = '.'): array |
||
58 | { |
||
59 | return $this->client->nlist($dir); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @inheritDoc |
||
64 | */ |
||
65 | public function download($path = '', $destination = false) |
||
66 | { |
||
67 | return $this->client->get($path, $destination); |
||
68 | } |
||
69 | } |
||
70 |