30,31c30,31
< 	function __construct($verb=FALSE, $le=FALSE) {
< 		parent::__construct(false, $verb, $le);
---
> 	function __construct( $verb = false, $le = false ) {
> 		parent::__construct( false, $verb, $le );
38,40c38,41
< 	function _settimeout($sock) {
< 		if(!@stream_set_timeout($sock, $this->_timeout)) {
< 			$this->PushError('_settimeout','socket set send timeout');
---
> 	function _settimeout( $sock ) {
> 
> 		if ( ! @stream_set_timeout( $sock, $this->_timeout ) ) {
> 			$this->PushError( '_settimeout','socket set send timeout' );
42c43
< 			return FALSE;
---
> 			return false;
44c45,46
< 		return TRUE;
---
> 
> 		return true;
47,52c49,55
< 	function _connect($host, $port) {
< 		$this->SendMSG("Creating socket");
< 		$sock = @fsockopen($host, $port, $errno, $errstr, $this->_timeout);
< 		if (!$sock) {
< 			$this->PushError('_connect','socket connect failed', $errstr." (".$errno.")");
< 			return FALSE;
---
> 	function _connect( $host, $port ) {
> 		$this->SendMSG( "Creating socket" );
> 		$sock = @fsockopen( $host, $port, $errno, $errstr, $this->_timeout );
> 
> 		if ( ! $sock ) {
> 			$this->PushError( '_connect','socket connect failed', $errstr." (".$errno.")" );
> 			return false;
54c57,58
< 		$this->_connected=true;
---
> 
> 		$this->_connected = true;
58,66c62,73
< 	function _readmsg($fnction="_readmsg"){
< 		if(!$this->_connected) {
< 			$this->PushError($fnction, 'Connect first');
< 			return FALSE;
< 		}
< 		$result=true;
< 		$this->_message="";
< 		$this->_code=0;
< 		$go=true;
---
> 	function _readmsg( $fnction = "_readmsg" ) {
> 
> 		if ( ! $this->_connected ) {
> 			$this->PushError( $fnction, 'Connect first' );
> 			return false;
> 		}
> 
> 		$result         = true;
> 		$this->_message = "";
> 		$this->_code    = 0;
> 		$go             = true;
> 
68,71c75,79
< 			$tmp=@fgets($this->_ftp_control_sock, 512);
< 			if($tmp===false) {
< 				$go=$result=false;
< 				$this->PushError($fnction,'Read failed');
---
> 			$tmp = @fgets( $this->_ftp_control_sock, 512 );
> 
> 			if ( false === $tmp ) {
> 				$go = $result = false;
> 				$this->PushError( $fnction, 'Read failed' );
73,74c81,84
< 				$this->_message.=$tmp;
< 				if(preg_match("/^([0-9]{3})(-(.*[".CRLF."]{1,2})+\\1)? [^".CRLF."]+[".CRLF."]{1,2}$/", $this->_message, $regs)) $go=false;
---
> 				$this->_message .= $tmp;
> 				if ( preg_match("/^([0-9]{3})(-(.*[" . CRLF . "]{1,2})+\\1)? [^" . CRLF . "]+[" . CRLF . "]{1,2}$/", $this->_message, $regs ) ) {
> 					$go = false;
> 				}
76,78c86,92
< 		} while($go);
< 		if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
< 		$this->_code=(int)$regs[1];
---
> 		} while ( $go );
> 
> 		if ( $this->LocalEcho ) {
> 			echo "GET < " . rtrim( $this->_message, CRLF ) . CRLF;
> 		}
> 
>         $this->_code = (int) $regs[1];
82,105c96,129
< 	function _exec($cmd, $fnction="_exec") {
< 		if(!$this->_ready) {
< 			$this->PushError($fnction,'Connect first');
< 			return FALSE;
< 		}
< 		if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
< 		$status=@fputs($this->_ftp_control_sock, $cmd.CRLF);
< 		if($status===false) {
< 			$this->PushError($fnction,'socket write failed');
< 			return FALSE;
< 		}
< 		$this->_lastaction=time();
< 		if(!$this->_readmsg($fnction)) return FALSE;
< 		return TRUE;
< 	}
< 
< 	function _data_prepare($mode=FTP_ASCII) {
< 		if(!$this->_settype($mode)) return FALSE;
< 		if($this->_passive) {
< 			if(!$this->_exec("PASV", "pasv")) {
< 				$this->_data_close();
< 				return FALSE;
< 			}
< 			if(!$this->_checkCode()) {
---
> 	function _exec( $cmd, $fnction = "_exec" ) {
> 
> 		if ( ! $this->_ready ) {
> 			$this->PushError( $fnction, 'Connect first' );
> 			return false;
> 		}
> 
> 		if ( $this->LocalEcho ) {
> 			echo "PUT > ", $cmd, CRLF;
> 		}
> 
> 		$status = @fputs( $this->_ftp_control_sock, $cmd . CRLF );
> 
> 		if ( false === $status) {
> 			$this->PushError( $fnction, 'socket write failed' );
> 			return false;
> 		}
> 
> 		$this->_lastaction = time();
> 		if ( ! $this->_readmsg( $fnction ) ) {
> 			return false;
> 		}
> 		return true;
> 	}
> 
> 	function _data_prepare( $mode = FTP_ASCII ) {
> 
> 		if ( ! $this->_settype( $mode ) ) {
> 			return false;
> 		}
> 
> 		if ( $this->_passive ) {
> 
> 			if ( ! $this->_exec( "PASV", "pasv" ) ) {
107c131
< 				return FALSE;
---
> 				return false;
109,115c133,134
< 			$ip_port = explode(",", preg_replace("/^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*$/s", "\\1", $this->_message));
< 			$this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
<             $this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
< 			$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
< 			$this->_ftp_data_sock=@fsockopen($this->_datahost, $this->_dataport, $errno, $errstr, $this->_timeout);
< 			if(!$this->_ftp_data_sock) {
< 				$this->PushError("_data_prepare","fsockopen fails", $errstr." (".$errno.")");
---
> 
> 			if ( ! $this->_checkCode() ) {
117c136
< 				return FALSE;
---
> 				return false;
119c138,151
< 			else $this->_ftp_data_sock;
---
> 
> 			$ip_port         = explode( ",", preg_replace("/^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*$/s", "\\1", $this->_message ) );
> 			$this->_datahost = $ip_port[0] . "." . $ip_port[1] . "." . $ip_port[2] . "." . $ip_port[3];
>             $this->_dataport = ( ( (int) $ip_port[4] ) << 8 ) + ( (int) $ip_port[5] );
> 			$this->SendMSG( "Connecting to " . $this->_datahost . ":" . $this->_dataport );
> 			$this->_ftp_data_sock = @fsockopen( $this->_datahost, $this->_dataport, $errno, $errstr, $this->_timeout );
> 
>             if ( ! $this->_ftp_data_sock ) {
>                 $this->push_error( '_data_prepare', 'fsockopen fails', $errstr . ' ( ' . $errno . ' )' );
>                 $this->_data_close();
>                 return false;
>             } 
> 
> 			return $this->_ftp_data_sock;
121,122c153,154
< 			$this->SendMSG("Only passive connections available!");
< 			return FALSE;
---
> 			$this->SendMSG( "Only passive connections available!" );
> 			return false;
124c156,157
< 		return TRUE;
---
> 
> 		return true;
127,138c160,182
< 	function _data_read($mode=FTP_ASCII, $fp=NULL) {
< 		if(is_resource($fp)) $out=0;
< 		else $out="";
< 		if(!$this->_passive) {
< 			$this->SendMSG("Only passive connections available!");
< 			return FALSE;
< 		}
< 		while (!feof($this->_ftp_data_sock)) {
< 			$block=fread($this->_ftp_data_sock, $this->_ftp_buff_size);
< 			if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_local], $block);
< 			if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
< 			else $out.=$block;
---
> 	function _data_read( $mode = FTP_ASCII, $fp = NULL ) {
> 		$out = "";
> 		if ( is_resource( $fp ) ) {
> 			$out = 0;
> 		}
> 
> 		if ( ! $this->_passive ) {
> 			$this->SendMSG( "Only passive connections available!" );
> 			return false;
> 		}
> 		
> 		while ( ! feof( $this->_ftp_data_sock ) ) {
> 			$block = fread( $this->_ftp_data_sock, $this->_ftp_buff_size );
> 
> 			if ( $mode != FTP_BINARY ) {
> 				$block = preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_local], $block );
> 			}
> 
> 			if( is_resource( $fp ) ) {
> 				$out += fwrite( $fp, $block, strlen( $block ) );
> 			} else {
> 				$out .= $block;
> 			}
139a184
> 
143,153c188,206
< 	function _data_write($mode=FTP_ASCII, $fp=NULL) {
< 		if(is_resource($fp)) $out=0;
< 		else $out="";
< 		if(!$this->_passive) {
< 			$this->SendMSG("Only passive connections available!");
< 			return FALSE;
< 		}
< 		if(is_resource($fp)) {
< 			while(!feof($fp)) {
< 				$block=fread($fp, $this->_ftp_buff_size);
< 				if(!$this->_data_write_block($mode, $block)) return false;
---
> 	function _data_write( $mode = FTP_ASCII, $fp=NULL ) {
> 		$out = "";
> 		if ( is_resource( $fp ) ) {
> 			$out = 0;
> 		} 
> 
> 		if ( ! $this->_passive ) {
> 			$this->SendMSG( "Only passive connections available!" );
> 			return false;
> 		}
> 
> 		if ( is_resource( $fp ) ) {
> 
> 			while ( ! feof( $fp ) ) {
> 				$block = fread( $fp, $this->_ftp_buff_size );
> 
> 				if( ! $this->_data_write_block( $mode, $block ) ) {
> 					return false;
> 				}
155,156c208,212
< 		} elseif(!$this->_data_write_block($mode, $fp)) return false;
< 		return TRUE;
---
> 		} elseif ( ! $this->_data_write_block( $mode, $fp ) ) {
> 			return false;
> 		}
> 		
> 		return true;
159,160c215,220
< 	function _data_write_block($mode, $block) {
< 		if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_remote], $block);
---
> 	function _data_write_block( $mode, $block ) {
> 
> 		if ( $mode != FTP_BINARY) {
> 			$block = preg_replace( "/\r\n|\r|\n/", $this->_eol_code[$this->OS_remote], $block );
> 		}
> 
162,164c222,225
< 			if(($t=@fwrite($this->_ftp_data_sock, $block))===FALSE) {
< 				$this->PushError("_data_write","Can't write to socket");
< 				return FALSE;
---
> 			$t = @fwrite( $this->_ftp_data_sock, $block );
> 			if ( false === $t ) {
> 				$this->push_error( '_data_write', "Can't write to socket" );
> 				return false;
166,167c227,229
< 			$block=substr($block, $t);
< 		} while(!empty($block));
---
> 			$block = substr( $block, $t );
> 		} while ( ! empty( $block ) );
> 
172,174c234,236
< 		@fclose($this->_ftp_data_sock);
< 		$this->SendMSG("Disconnected data from remote host");
< 		return TRUE;
---
> 		@fclose( $this->_ftp_data_sock );
> 		$this->SendMSG( "Disconnected data from remote host" );
> 		return true;
177,181c239,244
< 	function _quit($force=FALSE) {
< 		if($this->_connected or $force) {
< 			@fclose($this->_ftp_control_sock);
< 			$this->_connected=false;
< 			$this->SendMSG("Socket closed");
---
> 	function _quit( $force = false ) {
> 
> 		if ( $this->_connected || $force ) {
> 			@fclose( $this->_ftp_control_sock );
> 			$this->_connected = false;
> 			$this->SendMSG( "Socket closed" );
