public function get($remoteFile, $localFile)
    {
        $this->login();
        if (!isset($this->ssh)) {
            return false;
        }

        if (!$this->ssh->exec('scp -f ' . escapeshellarg($remoteFile), false)) { // -f = from
            return false;
        }

        $this->sendPacket("\0");

        if (!preg_match('#(?<perms>[^ ]+) (?<size>\d+) (?<name>.+)#', rtrim($this->receivePacket()), $info)) {
            return false;
        }

        $this->sendPacket("\0");

        $size = 0;

        $fp = null;
        if ($localFile !== false) {
            $fp = @fopen($localFile, 'wb');
            if (!$fp) {
                return false;
            }
        }

        $progressBar = new ProgressBar($this->output, $info['size']);
        $progressBar->setFormat(' %message% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%');
        $progressBar->start();

        $byteFormatter = new ByteFormatter();

        $content = '';
        while ($size < $info['size']) {
            $data = $this->receivePacket();
            // SCP usually seems to split stuff out into 16k chunks
            $length = strlen($data);
            $size += $length;
            $progressBar->advance($length);
            $progressBar->setMessage(
                sprintf('%s/%s', $byteFormatter->format($size), $byteFormatter->format($info['size']))
            );

            if (!$fp) {
                $content .= $data;
            } else {
                fwrite($fp, $data);
            }
        }

        $progressBar->finish();
        $this->output->writeln('');

        $this->closeChannel();

        return true;
    }
public function get($remoteFile, $localFile)
    {
        $this->login();
        if (!isset($this->ssh)) {
            return false;
        }

        if (!$this->ssh->exec('scp -f ' . escapeshellarg($remoteFile), false)) { // -f = from
            return false;
        }

        $this->sendPacket("\0");

        if (!preg_match('#(?<perms>[^ ]+) (?<size>\d+) (?<name>.+)#', rtrim($this->receivePacket()), $info)) {
            return false;
        }

        $this->sendPacket("\0");

        $size = 0;

        $fp = null;
        if ($localFile !== false) {
            $fp = @fopen($localFile, 'wb');
            if (!$fp) {
                return false;
            }
        }

        $progressBar = new ProgressBar($this->output, $info['size']);
        $progressBar->setFormat(' %message% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%');
        $progressBar->start();

        $byteFormatter = new ByteFormatter();

        $content = '';
        while ($size < $info['size']) {
            $data = $this->receivePacket();
            // SCP usually seems to split stuff out into 16k chunks
            $length = strlen($data);
            $size += $length;
            $progressBar->advance($length);
            $progressBar->setMessage(
                sprintf('%s/%s', $byteFormatter->format($size), $byteFormatter->format($info['size']))
            );

            if (!$fp) {
                $content .= $data;
            } else {
                fwrite($fp, $data);
            }
        }

        $progressBar->finish();
        $this->output->writeln('');

        $this->closeChannel();

        return true;
    }
public function get ( $ remoteFile , $ localFile ) { $ this -> login ( ) ; if ( ! isset ( $ this -> ssh ) ) { return false ; } if ( ! $ this -> ssh -> exec ( 'scp -f ' . escapeshellarg ( $ remoteFile ) , false ) ) { // -f = from return false ; } $ this -> sendPacket ( "\0" ) ; if ( ! preg_match ( '#(?<perms>[^ ]+) (?<size>\d+) (?<name>.+)#' , rtrim ( $ this -> receivePacket ( ) ) , $ info ) ) { return false ; } $ this -> sendPacket ( "\0" ) ; $ size = 0 ; $ fp = null ; if ( $ localFile !== false ) { $ fp = @ fopen ( $ localFile , 'wb' ) ; if ( ! $ fp ) { return false ; } } $ progressBar = new ProgressBar ( $ this -> output , $ info [ 'size' ] ) ; $ progressBar -> setFormat ( ' %message% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%' ) ; $ progressBar -> start ( ) ; $ byteFormatter = new ByteFormatter ( ) ; $ content = '' ; while ( $ size < $ info [ 'size' ] ) { $ data = $ this -> receivePacket ( ) ; // SCP usually seems to split stuff out into 16k chunks $ length = strlen ( $ data ) ; $ size += $ length ; $ progressBar -> advance ( $ length ) ; $ progressBar -> setMessage ( sprintf ( '%s/%s' , $ byteFormatter -> format ( $ size ) , $ byteFormatter -> format ( $ info [ 'size' ] ) ) ) ; if ( ! $ fp ) { $ content .= $ data ; } else { fwrite ( $ fp , $ data ) ; } } $ progressBar -> finish ( ) ; $ this -> output -> writeln ( '' ) ; $ this -> closeChannel ( ) ; return true ; }
Download remote-file and save it to given local-file.

@param string $remoteFile
@param string $localFile

@return bool
Download remote - file and save it to given local - file .