Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| PortCommand | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| run | |
0.00% |
0 / 11 |
|
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 React\Socket\ConnectionInterface; |
| 7 | |
| 8 | class PortCommand implements CommandInterface |
| 9 | { |
| 10 | public function run(ApieContext $apieContext, string $arg = ''): ApieContext |
| 11 | { |
| 12 | $conn = $apieContext->getContext(ConnectionInterface::class); |
| 13 | // Parse the argument: h1,h2,h3,h4,p1,p2 |
| 14 | $parts = explode(',', $arg); |
| 15 | if (count($parts) !== 6) { |
| 16 | $conn->write("501 Syntax error in parameters or arguments\r\n"); |
| 17 | return $apieContext; |
| 18 | } |
| 19 | $ip = implode('.', array_slice($parts, 0, 4)); |
| 20 | $port = ((int)$parts[4] << 8) + (int)$parts[5]; |
| 21 | // Store IP and port in context for later use |
| 22 | $apieContext = $apieContext->withContext(FtpConstants::IP, $ip) |
| 23 | ->withContext(FtpConstants::PORT, $port); |
| 24 | $conn->write("200 PORT command successful.\r\n"); |
| 25 | return $apieContext; |
| 26 | } |
| 27 | } |