Completed
Push — master ( a5146e...1ea8be )
by WEBEWEB
01:22
created

FtpsClient::connect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2020 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\Core\Network\FTP\Client;
13
14
use WBW\Library\Core\Network\FTP\Exception\FtpException;
15
use WBW\Library\Core\Security\Authenticator;
16
17
/**
18
 * FTPs client.
19
 *
20
 * @author webeweb <https://github.com/webeweb>
21
 * @package WBW\Library\Core\Network\FTP\Client
22
 */
23
class FtpsClient extends FtpClient {
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param Authenticator $authenticator The authenticator.
29
     */
30
    public function __construct(Authenticator $authenticator) {
31
        parent::__construct($authenticator);
32
33
        $this->getAuthenticator()->setScheme("ftps");
34
        if (null === $this->getAuthenticator()->getPort()) {
35
            $this->getAuthenticator()->setPort(990);
36
        }
37
    }
38
39
    /**
40
     * Connect.
41
     *
42
     * @param int $timeout The timeout.
43
     * @return FtpsClient Returns this FTPs client.
44
     * @throws FtpException Throws a FTP exception if an error occurs.
45
     */
46
    public function connect($timeout = 90) {
47
48
        $host = $this->getAuthenticator()->getHostname();
49
        $port = $this->getAuthenticator()->getPort();
50
51
        $this->setConnection(@ftp_ssl_connect($host, $port, $timeout));
52
        if (false === $this->getConnection()) {
53
            throw $this->newFtpException("ftp_ssl_connect failed: [${host}, ${port}, {$timeout}]");
54
        }
55
56
        return $this;
57
    }
58
}
59