diff options
| author | Tomas V.V.Cox <cox@php.net> | 2002-04-10 15:15:12 +0000 |
|---|---|---|
| committer | Tomas V.V.Cox <cox@php.net> | 2002-04-10 15:15:12 +0000 |
| commit | ca0b7690c80c12248e7e19fb6a1f7efff97b0ab1 (patch) | |
| tree | 165ce107dfdb79f2da5d72c2c7ecbd465a21e636 /pear/PEAR/Command/Remote.php | |
| parent | dfba9e63ab62378b2c501ad1e70572085a6e25c0 (diff) | |
| download | php-git-ca0b7690c80c12248e7e19fb6a1f7efff97b0ab1.tar.gz | |
Implemented "pear download <pakage>"
Diffstat (limited to 'pear/PEAR/Command/Remote.php')
| -rw-r--r-- | pear/PEAR/Command/Remote.php | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/pear/PEAR/Command/Remote.php b/pear/PEAR/Command/Remote.php index ecf2c3e91f..d5777d3c7a 100644 --- a/pear/PEAR/Command/Remote.php +++ b/pear/PEAR/Command/Remote.php @@ -30,7 +30,8 @@ class PEAR_Command_Remote extends PEAR_Command_Common { return array('remote-package-info', 'list-upgrades', - 'list-remote-packages'); + 'list-remote-packages', + 'download'); } // }}} @@ -61,6 +62,48 @@ class PEAR_Command_Remote extends PEAR_Command_Common case 'list-remote-packages': { break; } + case 'download': { + //$params[0] -> The package to download + if (count($params) != 1) { + return PEAR::raiseError("download expects one argument: the package to download"); + } + if (!ereg('^http://', $params[0])) { + $pkgfile = "http://" . $this->config->get('master_server') . + "/get/" . $params[0]; + } else { + $pkgfile = $params[0]; + } + if (!extension_loaded("zlib")) { + $pkgfile .= '?uncompress=yes'; + } + include_once 'HTTP.php'; + $headers = HTTP::head($pkgfile); + if (PEAR::isError($headers)|| !isset($headers['Content-disposition'])) { + return $this->raiseError("Could not retrieve remote file information"); + } + preg_match('|filename="(.*)"$|', $headers['Content-disposition'], $matches); + $fname = $matches[1]; + if (!$wp = @fopen($pkgfile, 'wb')) { + $failmsg = "Could not download $pkgfile"; break; + } + if (!$fp = @fopen($fname, 'wb')) { + $failmsg = "Could not write the file here"; break; + } + $bytes = 0; + $this->ui->displayLine("Downloading $pkgfile:"); + while ($data = @fread($wp, 16384)) { + $bytes += strlen($data); + if (!@fwrite($fp, $data)) { + return $this->raiseError("$pkgfile: write failed ($php_errormsg)"); + } + $this->ui->display('...'); + } + $this->ui->display(" done!\n"); + fclose($fp); + fclose($wp); + $this->ui->displayLine("File $fname downloaded ($bytes bytes)"); + break; + } case 'list-upgrades': { include_once "PEAR/Registry.php"; if (empty($params[0])) { |
