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