summaryrefslogtreecommitdiff
path: root/html/includes/ftp_class_pure.php
diff options
context:
space:
mode:
authorMatthijs Kuiper <info@matthijskuiper.nl>2018-01-15 22:53:54 +0100
committerMatthijs Kuiper <info@matthijskuiper.nl>2018-09-01 11:51:41 +0200
commita00f7e8976ad5ec1be0128fe7ccdae2d0c43b619 (patch)
treef437e4f694400657995c6064266bc9bfe445684c /html/includes/ftp_class_pure.php
parent3457a490dc8c9d92d23c540964a4e2d965c1c464 (diff)
ereg_match to preg_matchupdate-to-mysqli
Diffstat (limited to 'html/includes/ftp_class_pure.php')
-rw-r--r--html/includes/ftp_class_pure.php340
1 files changed, 172 insertions, 168 deletions
diff --git a/html/includes/ftp_class_pure.php b/html/includes/ftp_class_pure.php
index 4ec345e..9858c82 100644
--- a/html/includes/ftp_class_pure.php
+++ b/html/includes/ftp_class_pure.php
@@ -7,186 +7,190 @@
class ftp extends ftp_base {
- function ftp($verb=FALSE, $le=FALSE) {
- $this->LocalEcho = $le;
- $this->Verbose = $verb;
- $this->ftp_base();
- }
+ function ftp($verb=FALSE, $le=FALSE) {
+ $this->LocalEcho = $le;
+ $this->Verbose = $verb;
+ $this->ftp_base();
+ }
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Private functions -->
// <!-- --------------------------------------------------------------------------------------- -->
- function _settimeout($sock) {
- if(!@stream_set_timeout($sock, $this->_timeout)) {
- $this->PushError('_settimeout','socket set send timeout');
- $this->_quit();
- return FALSE;
- }
- return TRUE;
- }
+ function _settimeout($sock) {
+ if(!@stream_set_timeout($sock, $this->_timeout)) {
+ $this->PushError('_settimeout', 'socket set send timeout');
+ $this->_quit();
+ return FALSE;
+ }
+ return TRUE;
+ }
- function _connect($host, $port) {
- $this->SendMSG("NOT using PHP's socket extension");
- $this->SendMSG("Creating socket");
- $sock = @fsockopen($host, $port, $errno, $errstr, $this->_timeout);
- if (!$sock) {
- $this->PushError('_connect','socket connect failed', $errstr." (".$errno.")");
- return FALSE;
- }
- $this->_connected=true;
- return $sock;
- }
+ function _connect($host, $port) {
+ $this->SendMSG("NOT using PHP's socket extension");
+ $this->SendMSG("Creating socket");
+ $sock = @fsockopen($host, $port, $errno, $errstr, $this->_timeout);
+ if (!$sock) {
+ $this->PushError('_connect', 'socket connect failed', $errstr." (".$errno.")");
+ return FALSE;
+ }
+ $this->_connected=true;
+ return $sock;
+ }
- function _readmsg($fnction="_readmsg"){
- if(!$this->_connected) {
- $this->PushError($fnction, 'Connect first');
- return FALSE;
- }
- $result=true;
- $this->_message="";
- $this->_code=0;
- $go=true;
- do {
- $tmp=@my_fgets($this->_ftp_control_sock, 512);
- if($tmp===false) {
- $go=$result=false;
- $this->PushError($fnction,'Read failed');
- } else {
- $this->_message.=$tmp;
-// for($i=0; $i<strlen($this->_message); $i++)
-// if(ord($this->_message[$i])<32) echo "#".ord($this->_message[$i]); else echo $this->_message[$i];
-// echo CRLF;
- if(preg_match("/^([0-9]{3})(-(.*".CRLF.")+\\1)? [^".CRLF."]+".CRLF."$/", $this->_message, $regs)) $go=false;
- }
- } while($go);
- if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
- $this->_code=(int)$regs[1];
- return $result;
- }
+ function _readmsg($fnction="_readmsg"){
+ if(!$this->_connected) {
+ $this->PushError($fnction, 'Connect first');
+ return FALSE;
+ }
+ $result=true;
+ $this->_message="";
+ $this->_code=0;
+ $go=true;
+ do {
+ $tmp=@my_fgets($this->_ftp_control_sock, 512);
+ if($tmp===false) {
+ $go=$result=false;
+ $this->PushError($fnction, 'Read failed');
+ } else {
+ $this->_message.=$tmp;
+// for($i=0; $i<strlen($this->_message); $i++)
+// if(ord($this->_message[$i])<32) echo "#".ord($this->_message[$i]); else echo $this->_message[$i];
+// echo CRLF;
+ if (preg_match("/^([0-9]{3})(-(.*".CRLF.")+\\1)? [^".CRLF."]+".CRLF."$/", $this->_message, $regs)) $go=false;
+ }
+ } while($go);
+ if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
+ $this->_code=(int)$regs[1];
+ return $result;
+ }
- 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 _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($mode==FTP_BINARY) {
- if(!$this->_exec("TYPE I", "_data_prepare")) return FALSE;
- } else {
- if(!$this->_exec("TYPE A", "_data_prepare")) return FALSE;
- }
- if($this->_passive) {
- if(!$this->_exec("PASV", "pasv")) {
- $this->_data_close();
- return FALSE;
- }
- if(!$this->_checkCode()) {
- $this->_data_close();
- return FALSE;
- }
- $ip_port = explode(",", ereg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*".CRLF."$", "\\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.")");
- $this->_data_close();
- return FALSE;
- }
- else $this->_ftp_data_sock;
- } else {
- $this->SendMSG("Only passive connections available!");
- return FALSE;
- }
- return TRUE;
- }
+ function _data_prepare($mode=FTP_ASCII) {
+ if($mode==FTP_BINARY) {
+ if(!$this->_exec("TYPE I", "_data_prepare")) return FALSE;
+ } else {
+ if(!$this->_exec("TYPE A", "_data_prepare")) return FALSE;
+ }
+ if($this->_passive) {
+ if(!$this->_exec("PASV", "pasv")) {
+ $this->_data_close();
+ return FALSE;
+ }
+ if(!$this->_checkCode()) {
+ $this->_data_close();
+ return FALSE;
+ }
- function _data_read($mode=FTP_ASCII, $fp=NULL) {
- $NewLine=$this->NewLineCode[$this->OS_local];
- if(is_resource($fp)) $out=0;
- else $out="";
- if(!$this->_passive) {
- $this->SendMSG("Only passive connections available!");
- return FALSE;
- }
- if($mode!=FTP_BINARY) {
- while (!feof($this->_ftp_data_sock)) {
- $tmp=fread($this->_ftp_data_sock, 4096);
- $line.=$tmp;
- if(!preg_match("/".CRLF."$/", $line)) continue;
- $line=rtrim($line,CRLF).$NewLine;
- if(is_resource($fp)) $out+=fwrite($fp, $line, strlen($line));
- else $out.=$line;
- $line="";
- }
- } else {
- while (!feof($this->_ftp_data_sock)) {
- $block=fread($this->_ftp_data_sock, 4096);
- if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
- else $out.=$line;
- }
- }
- return $out;
- }
+ // $ip_port = explode(",", ereg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*".CRLF."$", "\\1", $this->_message));
+ preg_match("/\((.*?)\)/", $this->_message, $match);
+ $ip_port = explode(",", $match[1]);
- function _data_write($mode=FTP_ASCII, $fp=NULL) {
- $NewLine=$this->NewLineCode[$this->OS_local];
- 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)) {
- $line=my_fgets($fp, 4096);
- if($mode!=FTP_BINARY) $line=rtrim($line, CRLF).CRLF;
- do {
- if(($res=@fwrite($this->_ftp_data_sock, $line))===FALSE) {
- $this->PushError("_data_write","Can't write to socket");
- return FALSE;
- }
- $line=substr($line, $res);
- }while($line!="");
- }
- } else {
- if($mode!=FTP_BINARY) $fp=rtrim($fp, $NewLine).CRLF;
- do {
- if(($res=@fwrite($this->_ftp_data_sock, $fp))===FALSE) {
- $this->PushError("_data_write","Can't write to socket");
- return FALSE;
- }
- $fp=substr($fp, $res);
- }while($fp!="");
- }
- return TRUE;
- }
+ $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.")");
+ $this->_data_close();
+ return FALSE;
+ }
+ else $this->_ftp_data_sock;
+ } else {
+ $this->SendMSG("Only passive connections available!");
+ return FALSE;
+ }
+ return TRUE;
+ }
- function _data_close() {
- @fclose($this->_ftp_data_sock);
- $this->SendMSG("Disconnected data from remote host");
- return TRUE;
- }
+ function _data_read($mode=FTP_ASCII, $fp=NULL) {
+ $NewLine=$this->NewLineCode[$this->OS_local];
+ if(is_resource($fp)) $out=0;
+ else $out="";
+ if(!$this->_passive) {
+ $this->SendMSG("Only passive connections available!");
+ return FALSE;
+ }
+ if($mode!=FTP_BINARY) {
+ while (!feof($this->_ftp_data_sock)) {
+ $tmp=fread($this->_ftp_data_sock, 4096);
+ $line.=$tmp;
+ if(!preg_match("/".CRLF."$/", $line)) continue;
+ $line=rtrim($line,CRLF).$NewLine;
+ if(is_resource($fp)) $out+=fwrite($fp, $line, strlen($line));
+ else $out.=$line;
+ $line="";
+ }
+ } else {
+ while (!feof($this->_ftp_data_sock)) {
+ $block=fread($this->_ftp_data_sock, 4096);
+ if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
+ else $out.=$line;
+ }
+ }
+ return $out;
+ }
- function _quit($force=FALSE) {
- if($this->_connected or $force) {
- @fclose($this->_ftp_control_sock);
- $this->_connected=false;
- $this->SendMSG("Socket closed");
- }
- }
+ function _data_write($mode=FTP_ASCII, $fp=NULL) {
+ $NewLine=$this->NewLineCode[$this->OS_local];
+ 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)) {
+ $line=my_fgets($fp, 4096);
+ if($mode!=FTP_BINARY) $line=rtrim($line, CRLF).CRLF;
+ do {
+ if(($res=@fwrite($this->_ftp_data_sock, $line))===FALSE) {
+ $this->PushError("_data_write","Can't write to socket");
+ return FALSE;
+ }
+ $line=substr($line, $res);
+ }while($line!="");
+ }
+ } else {
+ if($mode!=FTP_BINARY) $fp=rtrim($fp, $NewLine).CRLF;
+ do {
+ if(($res=@fwrite($this->_ftp_data_sock, $fp))===FALSE) {
+ $this->PushError("_data_write","Can't write to socket");
+ return FALSE;
+ }
+ $fp=substr($fp, $res);
+ }while($fp!="");
+ }
+ return TRUE;
+ }
+
+ function _data_close() {
+ @fclose($this->_ftp_data_sock);
+ $this->SendMSG("Disconnected data from remote host");
+ return TRUE;
+ }
+
+ function _quit($force=FALSE) {
+ if($this->_connected or $force) {
+ @fclose($this->_ftp_control_sock);
+ $this->_connected=false;
+ $this->SendMSG("Socket closed");
+ }
+ }
}
?>