Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| RetrCommand | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
3.00 | |
0.00% |
0 / 1 |
| run | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
3.00 | |||
| 1 | <?php |
| 2 | namespace Apie\FtpServer\Commands; |
| 3 | |
| 4 | use Apie\ApieFileSystem\Virtual\VirtualFolderInterface; |
| 5 | use Apie\Core\Context\ApieContext; |
| 6 | use Apie\Core\ValueObjects\Utils; |
| 7 | use Apie\FtpServer\FtpConstants; |
| 8 | use Apie\FtpServer\Transfers\TransferInterface; |
| 9 | use React\Socket\ConnectionInterface; |
| 10 | |
| 11 | class RetrCommand implements CommandInterface |
| 12 | { |
| 13 | public function run(ApieContext $apieContext, string $arg = ''): ApieContext |
| 14 | { |
| 15 | $conn = $apieContext->getContext(ConnectionInterface::class); |
| 16 | if (!$arg) { |
| 17 | $conn->write("501 Missing filename\r\n"); |
| 18 | } else { |
| 19 | $folder = $apieContext->getContext(FtpConstants::CURRENT_FOLDER); |
| 20 | assert($folder instanceof VirtualFolderInterface); |
| 21 | $file = $folder->getChild($arg); |
| 22 | $transfer = $apieContext->getContext(TransferInterface::class); |
| 23 | assert($transfer instanceof TransferInterface); |
| 24 | if ($file === null) { |
| 25 | $conn->write("550 File not found\r\n"); |
| 26 | } else { |
| 27 | $conn->write("150 Opening data connection\r\n"); |
| 28 | $transfer->send(Utils::toString($file->getContents())); |
| 29 | $conn->write("226 Transfer complete\r\n"); |
| 30 | } |
| 31 | } |
| 32 | return $apieContext; |
| 33 | } |
| 34 | } |