Altax\Module\Task\Process\Process::get PHP Method

get() public method

public get ( $remote, $local )
    public function get($remote, $local)
    {
        if (!$this->node) {
            throw new \RuntimeException("Node is not defined to get a file.");
        }
        $this->runtimeTask->getOutput()->writeln($this->getRemoteInfoPrefix() . "<info>Get: </info>{$remote} -> {$local}");
        $sftp = $this->getSFTP();
        if (!is_dir(dirname($local))) {
            $fs = new Filesystem();
            $fs->mkdir(dirname($local));
            if ($this->runtimeTask->getOutput()->isVerbose()) {
                $this->runtimeTask->getOutput()->writeln($this->getRemoteInfoPrefix() . "<info>Create directory: </info>" . dirname($local));
            }
        }
        $ret = $sftp->get($remote, $local);
        if ($ret === false) {
            throw new \RuntimeException("Couldn't get: {$remote} -> {$local}");
        }
        return $ret;
    }

Usage Example

示例#1
0
 public function testGet2()
 {
     $srcPath = "/NotExistsFile/gettest.txt";
     $destPath = __DIR__ . "/../../../../tmp/Altax/Module/Task/Process/ProcessTest/gettest.txt";
     $this->runtimeTask->getOutput()->setVerbosity(3);
     $node = new Node();
     $node->setName("127.0.0.1");
     $process = new Process($this->runtimeTask, $node);
     try {
         $process->get($srcPath, $destPath);
         $this->assertEquals(false, true);
     } catch (\RuntimeException $e) {
         $this->assertEquals(true, true);
     }
 }