1 | <?php |
||
13 | class Ftp implements AdapterInterface |
||
14 | { |
||
15 | const FTP_MODE_ASCII = FTP_ASCII; |
||
16 | const FTP_MODE_BINARY = FTP_BINARY; |
||
17 | |||
18 | protected $transfer_mode = self::FTP_MODE_ASCII; |
||
19 | protected $host = ''; |
||
20 | protected $username = ''; |
||
21 | protected $password = ''; |
||
22 | protected $filename = ''; |
||
23 | protected $port = 21; |
||
24 | |||
25 | protected $timeout = 90; |
||
26 | protected $handle = null; |
||
27 | |||
28 | /** |
||
29 | * You might think just connect to the ftp server from the constructor |
||
30 | * but psr-4 dictates that autoloadable classes MUST NOT... |
||
31 | * |
||
32 | * Quote: |
||
33 | * Autoloader implementations MUST NOT throw exceptions, MUST NOT raise errors of any level, and SHOULD NOT return a value. |
||
34 | * |
||
35 | * So we need to use authenticate() after we construct. |
||
36 | * |
||
37 | * @param string $host |
||
38 | * @param string $username |
||
39 | * @param string $password |
||
40 | * @param string $filename |
||
41 | * @param int $port |
||
42 | * @param int $timeout |
||
43 | */ |
||
44 | public function __construct($host = "", $username = "", $password = "", $filename = "", $port = 21, $timeout = 90) |
||
45 | { |
||
46 | $this->host = $host; |
||
47 | $this->username = $username; |
||
48 | $this->password = $password; |
||
49 | $this->filename = $filename; |
||
50 | $this->timeout = $timeout; |
||
51 | $this->port = $port; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Set the connection transfer mode to FTP_MODE_ASCII or FTP_MODE_BINARY. |
||
56 | * |
||
57 | * @param $transfer_mode |
||
58 | */ |
||
59 | public function setTransferMode($transfer_mode) |
||
63 | |||
64 | /** |
||
65 | * Return the current TransferMode. |
||
66 | * |
||
67 | * @return int |
||
68 | */ |
||
69 | public function getTransferMode() |
||
73 | |||
74 | /** |
||
75 | * Set passive mode on or off. Please not that you can |
||
76 | * only use this mode after you have authenticated the user. |
||
77 | * |
||
78 | * @param bool $status |
||
79 | * @return mixed |
||
80 | */ |
||
81 | public function setPassiveMode(bool $status) |
||
85 | |||
86 | /** |
||
87 | * Disable passive mode and switch to active mode. |
||
88 | */ |
||
89 | public function setActiveMode() |
||
93 | |||
94 | /** |
||
95 | * We should be so nice to terminate the construction of we are done. |
||
96 | */ |
||
97 | public function __destruct() |
||
98 | { |
||
99 | if ($this->handle) { |
||
100 | ftp_close($this->handle); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Authenticate to the ftp server. |
||
106 | * |
||
107 | * @return bool |
||
108 | */ |
||
109 | public function authenticate() |
||
132 | |||
133 | /** |
||
134 | * Read the previous scan results from the file system. |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | public function read() |
||
164 | |||
165 | /** |
||
166 | * Write the report to the filesystem so we can reuse it |
||
167 | * at a later stace when we invoke Redbox\Scan\ScanService's scan() method. |
||
168 | * |
||
169 | * @param Report\Report|null $report |
||
170 | * @return bool |
||
171 | */ |
||
172 | public function write(Report\Report $report = null) |
||
193 | } |