* @copyright Alexey Dotsenko
* @author Alexey Dotsenko
* @link http://www.phpclasses.org/browse/package/1743.html Site
- * @license LGPL License http://www.opensource.org/licenses/lgpl-license.html
+ * @license LGPL http://www.opensource.org/licenses/lgpl-license.html
+ */
+
+/**
+ * Defines the newline characters, if not defined already.
+ *
+ * This can be redefined.
+ *
+ * @since 2.5
+ * @var string
*/
if(!defined('CRLF')) define('CRLF',"\r\n");
+
+/**
+ * Sets whatever to autodetect ASCII mode.
+ *
+ * This can be redefined.
+ *
+ * @since 2.5
+ * @var int
+ */
if(!defined("FTP_AUTOASCII")) define("FTP_AUTOASCII", -1);
+
+/**
+ *
+ * This can be redefined.
+ * @since 2.5
+ * @var int
+ */
if(!defined("FTP_BINARY")) define("FTP_BINARY", 1);
+
+/**
+ *
+ * This can be redefined.
+ * @since 2.5
+ * @var int
+ */
if(!defined("FTP_ASCII")) define("FTP_ASCII", 0);
-if(!defined('FTP_FORCE')) define('FTP_FORCE', TRUE);
+
+/**
+ * Whether to force FTP.
+ *
+ * This can be redefined.
+ *
+ * @since 2.5
+ * @var bool
+ */
+if(!defined('FTP_FORCE')) define('FTP_FORCE', true);
+
+/**
+ * @since 2.5
+ * @var string
+ */
define('FTP_OS_Unix','u');
+
+/**
+ * @since 2.5
+ * @var string
+ */
define('FTP_OS_Windows','w');
+
+/**
+ * @since 2.5
+ * @var string
+ */
define('FTP_OS_Mac','m');
+/**
+ * PemFTP base class
+ *
+ */
class ftp_base {
/* Public variables */
var $LocalEcho;
var $AutoAsciiExt;
/* Constructor */
- function ftp_base($port_mode=FALSE) {
- $this->__construct($port_mode);
- }
-
function __construct($port_mode=FALSE, $verb=FALSE, $le=FALSE) {
$this->LocalEcho=$le;
$this->Verbose=$verb;
elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') $this->OS_local=FTP_OS_Mac;
}
+ function ftp_base($port_mode=FALSE) {
+ $this->__construct($port_mode);
+ }
+
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Public functions -->
// <!-- --------------------------------------------------------------------------------------- -->
$dns=@gethostbyaddr($host);
if(!$ip) $ip=$host;
if(!$dns) $dns=$host;
- if(ip2long($ip) === -1) {
+ // Validate the IPAddress PHP4 returns -1 for invalid, PHP5 false
+ // -1 === "255.255.255.255" which is the broadcast address which is also going to be invalid
+ $ipaslong = ip2long($ip);
+ if ( ($ipaslong == false) || ($ipaslong === -1) ) {
$this->SendMSG("Wrong host name/address \"".$host."\"");
return FALSE;
}
function pwd() {
if(!$this->_exec("PWD", "pwd")) return FALSE;
if(!$this->_checkCode()) return FALSE;
- return ereg_replace("^[0-9]{3} \"(.+)\".+", "\\1", $this->_message);
+ return preg_replace("/^[0-9]{3} \"(.+)\".*$/s", "\\1", $this->_message);
}
function cdup() {
}
if(!$this->_exec("SIZE ".$pathname, "filesize")) return FALSE;
if(!$this->_checkCode()) return FALSE;
- return ereg_replace("^[0-9]{3} ([0-9]+)".CRLF, "\\1", $this->_message);
+ return preg_replace("/^[0-9]{3} ([0-9]+).*$/s", "\\1", $this->_message);
}
function abort() {
}
if(!$this->_exec("MDTM ".$pathname, "mdtm")) return FALSE;
if(!$this->_checkCode()) return FALSE;
- $mdtm = ereg_replace("^[0-9]{3} ([0-9]+)".CRLF, "\\1", $this->_message);
+ $mdtm = preg_replace("/^[0-9]{3} ([0-9]+).*$/s", "\\1", $this->_message);
$date = sscanf($mdtm, "%4d%2d%2d%2d%2d%2d");
$timestamp = mktime($date[3], $date[4], $date[5], $date[1], $date[2], $date[0]);
return $timestamp;
$this->_features=array();
foreach($f as $k=>$v) {
$v=explode(" ", trim($v));
- $this->_features[array_shift($v)]=$v;;
+ $this->_features[array_shift($v)]=$v;
}
return true;
}
return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "LIST", "rawlist");
}
- function nlist($pathname="") {
+ function nlist($pathname="", $arg="") {
return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "NLST", "nlist");
}
}
foreach($list as $k=>$v) {
$list[$k]=$this->parselisting($v);
- if($list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
+ if( ! $list[$k] or $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
}
$ret=true;
foreach($list as $el) {
foreach($list as $k=>$v) {
$list[$k]=$this->parselisting($v);
- if($list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
+ if( ! $list[$k] or $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
}
$ret=true;
function glob_regexp($pattern,$probe) {
$sensitive=(PHP_OS!='WIN32');
return ($sensitive?
- ereg($pattern,$probe):
- eregi($pattern,$probe)
+ preg_match( '/' . preg_quote( $pattern, '/' ) . '/', $probe ) :
+ preg_match( '/' . preg_quote( $pattern, '/' ) . '/i', $probe )
);
}
}
}
-$mod_sockets=TRUE;
-if (!extension_loaded('sockets')) {
- $prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : '';
- if(!@dl($prefix . 'sockets.' . PHP_SHLIB_SUFFIX)) $mod_sockets=FALSE;
+$mod_sockets = extension_loaded( 'sockets' );
+if ( ! $mod_sockets && function_exists( 'dl' ) && is_callable( 'dl' ) ) {
+ $prefix = ( PHP_SHLIB_SUFFIX == 'dll' ) ? 'php_' : '';
+ @dl( $prefix . 'sockets.' . PHP_SHLIB_SUFFIX );
+ $mod_sockets = extension_loaded( 'sockets' );
}
-require_once "class-ftp-".($mod_sockets?"sockets":"pure").".php";
-?>
+
+require_once dirname( __FILE__ ) . "/class-ftp-" . ( $mod_sockets ? "sockets" : "pure" ) . ".php";