Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| EpsvCommand | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| run | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace Apie\FtpServer\Commands; |
| 3 | |
| 4 | use Apie\Core\Context\ApieContext; |
| 5 | use Apie\FtpServer\FtpConstants; |
| 6 | use Apie\FtpServer\Transfers\PasvTransfer; |
| 7 | use Apie\FtpServer\Transfers\TransferInterface; |
| 8 | use React\Socket\ConnectionInterface; |
| 9 | |
| 10 | class EpsvCommand implements CommandInterface |
| 11 | { |
| 12 | public function run(ApieContext $apieContext, string $arg = ''): ApieContext |
| 13 | { |
| 14 | $conn = $apieContext->getContext(ConnectionInterface::class); |
| 15 | |
| 16 | $transfer = $apieContext->getContext(TransferInterface::class, false); |
| 17 | if ($transfer instanceof PasvTransfer) { |
| 18 | $transfer->end(); |
| 19 | } |
| 20 | |
| 21 | $transfer = new PasvTransfer( |
| 22 | $apieContext->getContext(FtpConstants::PASV_MIN_PORT, false) ?? '49152', |
| 23 | $apieContext->getContext(FtpConstants::PASV_MAX_PORT, false) ?? '65534', |
| 24 | ); |
| 25 | $address = $transfer->getAddress(); |
| 26 | $port = parse_url($address, PHP_URL_PORT); |
| 27 | |
| 28 | $conn->write("229 Entering Extended Passive Mode (|||$port|)\r\n"); |
| 29 | |
| 30 | return $apieContext->withContext(TransferInterface::class, $transfer); |
| 31 | } |
| 32 | } |