http://cvs.php.net/viewcvs.cgi/pear-core/PEAR/Command/Remoteinstall.php?r1=1.2&r2=1.3&diff_format=u Index: pear-core/PEAR/Command/Remoteinstall.php diff -u pear-core/PEAR/Command/Remoteinstall.php:1.2 pear-core/PEAR/Command/Remoteinstall.php:1.3 --- pear-core/PEAR/Command/Remoteinstall.php:1.2 Fri Jan 6 04:47:36 2006 +++ pear-core/PEAR/Command/Remoteinstall.php Sun Apr 2 23:14:59 2006 @@ -16,7 +16,7 @@ * @author Greg Beaver * @copyright 1997-2006 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Remoteinstall.php,v 1.2 2006/01/06 04:47:36 cellog Exp $ + * @version CVS: $Id: Remoteinstall.php,v 1.3 2006/04/02 23:14:59 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 0.1 */ @@ -26,6 +26,7 @@ */ require_once 'PEAR/Command/Install.php'; +define('PEAR_REMOTEINSTALL_OK', 1); /** * PEAR commands for installation or deinstallation/upgrading of * packages. @@ -329,6 +330,11 @@ } elseif (!$this->config->get('remote_config')) { return $this->raiseError('Error: ' . $command . ' expects either option ' . '"remoteconfig" be set, or remote_config configuration variable be used'); + } else { + $e = $this->config->readFTPConfigFile($this->config->get('remote_config')); + if (!PEAR::isError($e)) { + $this->installer->setConfig($this->config); + } } $command = str_replace('remote-', '', $command); // fool parent return parent::doInstall($command, $options, $params); @@ -350,6 +356,11 @@ } elseif (!$this->config->get('remote_config')) { return $this->raiseError('Error: ' . $command . ' expects either option ' . '"remoteconfig" be set, or remote_config configuration variable be used'); + } else { + $e = $this->config->readFTPConfigFile($this->config->get('remote_config')); + if (!PEAR::isError($e)) { + $this->installer->setConfig($this->config); + } } $command = 'uninstall'; // fool parent return parent::doUninstall($command, $options, $params); @@ -357,4 +368,10 @@ // }}} } + +/** + * This is a hack for PEAR 1.4.x to work + * @ignore + */ +class Net_FTP {} ?> http://cvs.php.net/viewcvs.cgi/pear-core/PEAR/Config.php?r1=1.126&r2=1.127&diff_format=u Index: pear-core/PEAR/Config.php diff -u pear-core/PEAR/Config.php:1.126 pear-core/PEAR/Config.php:1.127 --- pear-core/PEAR/Config.php:1.126 Sun Mar 26 23:24:50 2006 +++ pear-core/PEAR/Config.php Sun Apr 2 23:14:59 2006 @@ -16,7 +16,7 @@ * @author Greg Beaver * @copyright 1997-2006 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Config.php,v 1.126 2006/03/26 23:24:50 cellog Exp $ + * @version CVS: $Id: Config.php,v 1.127 2006/04/02 23:14:59 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 0.1 */ @@ -688,17 +688,15 @@ function readFTPConfigFile($path) { do { // poor man's try - if (!class_exists('Net_FTP')) { + if (!class_exists('PEAR_FTP')) { if (!class_exists('PEAR_Common')) { require_once 'PEAR/Common.php'; } - if (PEAR_Common::isIncludeable('Net/FTP.php')) { - include_once 'Net/FTP.php'; + if (PEAR_Common::isIncludeable('PEAR/FTP.php')) { + require_once 'PEAR/FTP.php'; } } - if (class_exists('Net_FTP') && - (class_exists('PEAR_FTP') || PEAR_Common::isIncludeable('PEAR/FTP.php'))) { - require_once 'PEAR/FTP.php'; + if (class_exists('PEAR_FTP')) { $this->_ftp = &new PEAR_FTP; $this->_ftp->pushErrorHandling(PEAR_ERROR_RETURN); $e = $this->_ftp->init($path); http://cvs.php.net/viewcvs.cgi/pear-core/PEAR/FTP.php?r1=1.6&r2=1.7&diff_format=u Index: pear-core/PEAR/FTP.php diff -u pear-core/PEAR/FTP.php:1.6 pear-core/PEAR/FTP.php:1.7 --- pear-core/PEAR/FTP.php:1.6 Fri Jan 6 04:47:36 2006 +++ pear-core/PEAR/FTP.php Sun Apr 2 23:14:59 2006 @@ -15,7 +15,7 @@ * @author Greg Beaver * @copyright 1997-2006 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: FTP.php,v 1.6 2006/01/06 04:47:36 cellog Exp $ + * @version CVS: $Id: FTP.php,v 1.7 2006/04/02 23:14:59 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 1.4.0a1 */ @@ -31,55 +31,66 @@ * @link http://pear.php.net/package/PEAR * @since Class available since Release 1.4.0a1 */ -class PEAR_FTP extends Net_FTP +class PEAR_FTP extends PEAR { /** * @var array * @access private */ - var $_parsed; + protected $_parsed; + + /** + * URI to prepend to all paths + * @var string + */ + protected $_uri; /** * @param string full url to remote config file * @return true|PEAR_Error */ - function init($url = null) + public function init($url = null) { if ($url !== null) { $this->_parsed = @parse_url($url); + } else { + return; } if (!isset($this->_parsed['host'])) { return PEAR::raiseError('No FTP Host specified'); } + if (!isset($this->_parsed['scheme'])) { + return PEAR::raiseError('No FTP Scheme (ftp/ftps) specified'); + } + if (!in_array($this->_parsed['scheme'], array('ftp', 'ftps'), true)) { + return PEAR::raiseError('Only ftp/ftps is supported for remote config'); + } + if (!in_array($this->_parsed['scheme'], stream_get_wrappers(), true)) { + if ($this->_parsed['scheme'] == 'ftps' && !extension_loaded('openssl')) { + if (OS_WINDOWS) { + return PEAR::raiseError('In order to use ftps, you must ' . + 'put "extension=php_openssl.dll" into php.ini and ' . + 'copy libeay32.dll and ssleay32.dll to \windows\system32'); + } else { + return PEAR::raiseError('In order to use ftps, you must ' . + 'enable the "openssl" extension in php.ini'); + } + } + return PEAR::raiseError('Your PHP does not support this wrapper: ' . + $this->_parsed['scheme']); + } if (!isset($this->_parsed['path'])) { return PEAR::raiseError('No FTP file path to remote config specified'); } $host = $this->_parsed['host']; - $user = @$this->_parsed['user']; - $pass = @$this->_parsed['pass']; - $port = @$this->_parsed['port']; - $path = @$this->_parsed['path']; - $this->Net_FTP($host, $port, 30); // 30 second timeout - $this->pushErrorHandling(PEAR_ERROR_RETURN); - $e = $this->connect(); - if (PEAR::isError($e)) { - $this->popErrorHandling(); - return $e; - } - $e = $this->login($user, $pass); - if (PEAR::isError($e)) { - $this->popErrorHandling(); - return $e; - } - $path = dirname($path); - if ($path == '\\') { // windows will do this - $path = '/'; - } - $e = $this->cd($path); - if (PEAR::isError($e)) { - $this->popErrorHandling(); - return $e; + $pass = isset($this->_parsed['pass']) ? ':' . $this->_parsed['pass'] : ''; + $user = isset($this->_parsed['user']) ? $this->_parsed['user'] . "$pass@" : ''; + $port = isset($this->_parsed['port']) ? ':' . $this->_parsed['port'] : ''; + $path = dirname($this->_parsed['path']); + if ($path[strlen($path) - 1] == '/') { + $path = substr($path, 0, strlen($path) - 1); } + $this->_uri = $this->_parsed['scheme'] . '://' . $user . $host . $path; return true; } @@ -89,44 +100,21 @@ * selected server-path. (see: pwd()) * * @access public - * @param string $dir Absolute or relative dir-path + * @param string $dir relative dir-path * @param bool $recursive (optional) Create all needed directories * @return mixed True on success, otherwise PEAR::Error * @see NET_FTP_ERR_CREATEDIR_FAILED */ - function mkdir($dir, $recursive = false) + public function mkdir($dir, $recursive = false) { - $dir = $this->_construct_path($dir); - $savedir = $this->pwd(); - $this->pushErrorHandling(PEAR_ERROR_RETURN); - $e = $this->cd($dir); - $this->popErrorHandling(); - if ($e === true) { - $this->cd($savedir); - return true; + if (method_exists($this, '_testftp_mkdir')) { + $res = $this->_testftp_mkdir($this->_prepend($dir), 0755, $recursive); + } else { + $res = @mkdir($this->_prepend($dir), 0755, $recursive); } - $this->cd($savedir); - if ($recursive === false) { - if (method_exists($this, '_testftp_mkdir')) { - $res = $this->_testftp_mkdir($this->_handle, $dir); - } else { - $res = @ftp_mkdir($this->_handle, $dir); - } - if (!$res) { - return $this->raiseError("Creation of '$dir' failed", NET_FTP_ERR_CREATEDIR_FAILED); - } else { - return true; - } + if (!$res) { + return $this->raiseError("Creation of '$dir' failed"); } else { - if(strpos($dir, '/') === false) { - return $this->mkdir($dir,false); - } - $pos = 0; - $res = $this->mkdir(dirname($dir), true); - $res = $this->mkdir($dir, false); - if ($res !== true) { - return $res; - } return true; } } @@ -135,12 +123,67 @@ * @param string full path to local file * @param string full path to remote file */ - function installFile($local, $remote) + public function installFile($local, $remote) { $this->pushErrorHandling(PEAR_ERROR_RETURN); $this->mkdir(dirname($remote), true); $this->popErrorHandling(); return $this->put($local, $remote, true); } + + /** + * Retrieve a file from the remote server + * + * @param string $relfile relative path of the remote file + * @param string $localfile full local path to save the file in + */ + public function get($relfile, $localfile, $binary = true) + { + $local = fopen($localfile, 'w' . ($binary ? 'b' : '')); + $remote = fopen($this->_prepend($relfile), 'r' . ($binary ? 'b' : '')); + $ret = stream_copy_to_stream($remote, $local); + fclose($local); + fclose($remote); + return $ret ? $ret : PEAR::raiseError('FTP get of ' . $this->_prepend($remotefile) . + ' failed'); + } + + public function put($local, $remotefile, $overwrite = false) + { + $local = fopen($localfile, 'r' . ($binary ? 'b' : '')); + $opts = array('ftp' => array('overwrite' => $overwrite)); + $context = stream_context_create($opts); + $remote = fopen($this->_prepend($remotefile), 'r' . ($binary ? 'b' : ''), false, + $context); + $ret = stream_copy_to_stream($remote, $local); + fclose($local); + fclose($remote); + return $ret ? $ret : PEAR::raiseError('FTP put of ' . $this->_prepend($remotefile) . + ' failed'); + } + + public function disconnect() + { + // does nothing here + } + + public function rm($path, $recursive = false) + { + if (unlink($this->_prepend($path))) { + return true; + } + return PEAR::raiseError('rm of ' . $this->_prepend($path) . ' failed'); + } + + /** + * Return a ftp URI for usage with filesystem functions directly + * + * @param string $path relative path to the on the FTP server + * @return string full path to the ftp server including ftp[s]://... + */ + private function _prepend($path) + { + return $this->_uri . '/' . $path; + } } ?> \ No newline at end of file http://cvs.php.net/viewcvs.cgi/pear-core/PEAR/RemoteInstaller.php?r1=1.3&r2=1.4&diff_format=u Index: pear-core/PEAR/RemoteInstaller.php diff -u pear-core/PEAR/RemoteInstaller.php:1.3 pear-core/PEAR/RemoteInstaller.php:1.4 --- pear-core/PEAR/RemoteInstaller.php:1.3 Fri Jan 6 04:51:56 2006 +++ pear-core/PEAR/RemoteInstaller.php Sun Apr 2 23:14:59 2006 @@ -18,7 +18,7 @@ * @author Greg Beaver * @copyright 2005-2006 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: RemoteInstaller.php,v 1.3 2006/01/06 04:51:56 cellog Exp $ + * @version CVS: $Id: RemoteInstaller.php,v 1.4 2006/04/02 23:14:59 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 0.1.0 */ @@ -87,7 +87,7 @@ /** * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2 */ - function ftpUninstall($pkg) + public function ftpUninstall($pkg) { $ftp = &$this->config->getFTP(); if (!$ftp) { @@ -160,8 +160,12 @@ * Upload an installed package - does not work with register-only packages! * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2 */ - function ftpInstall($pkg) + public function ftpInstall($pkg) { + if ($pkg->getType() != 'php') { + return PEAR::raiseError('Error: can only install PHP scripts remotely,' . + ' no PHP extensions can be compiled remotely'); + } $ftp = &$this->config->getFTP(); if (!$ftp) { return PEAR::raiseError('FTP client not initialized'); http://cvs.php.net/viewcvs.cgi/pear-core/package-RemoteInstall.xml?r1=1.4&r2=1.5&diff_format=u Index: pear-core/package-RemoteInstall.xml diff -u pear-core/package-RemoteInstall.xml:1.4 pear-core/package-RemoteInstall.xml:1.5 --- pear-core/package-RemoteInstall.xml:1.4 Fri Nov 4 23:17:56 2005 +++ pear-core/package-RemoteInstall.xml Sun Apr 2 23:14:59 2006 @@ -27,26 +27,26 @@ yes + Pierre-Alain Joye + pajoye + pajoye@xxxxxxxxxx + yes + + Stig Bakken ssb stig@xxxxxxx - yes + no Tomas V.V.Cox cox cox@xxxxxxxxxxx - yes + no - - Pierre-Alain Joye - pajoye - pajoye@xxxxxxxxxx - yes - - 2005-11-03 + 2006-03-29 - 0.2.0 + 0.3.0 0.1.0 @@ -55,7 +55,9 @@ PHP License - Update to new format needed by PEAR 1.4.3 + Support for FTPS is now available + Drop Net_FTP dependency, add dependency on PHP 5, use streams to access + FTP. @@ -78,22 +80,16 @@ - 4.2 + 5.0.0 - 1.4.0a12 + 1.4.3 PEAR pear.php.net 1.4.3 - - Net_FTP - pear.php.net - 1.3.0RC1 - 1.3.1 - @@ -113,5 +109,20 @@ initial separate release from PEAR + + + 0.2.0 + 0.1.0 + + + alpha + alpha + + 2005-11-29 + PHP License + + Update to new format needed by PEAR 1.4.3 + +