Edit File by line
/home/zeestwma/richards.../wp-admin/includes
File: class-ftp-pure.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* PemFTP - An Ftp implementation in pure PHP
[2] Fix | Delete
*
[3] Fix | Delete
* @package PemFTP
[4] Fix | Delete
* @since 2.5.0
[5] Fix | Delete
*
[6] Fix | Delete
* @version 1.0
[7] Fix | Delete
* @copyright Alexey Dotsenko
[8] Fix | Delete
* @author Alexey Dotsenko
[9] Fix | Delete
* @link https://www.phpclasses.org/package/1743-PHP-FTP-client-in-pure-PHP.html
[10] Fix | Delete
* @license LGPL https://opensource.org/licenses/lgpl-license.html
[11] Fix | Delete
*/
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* FTP implementation using fsockopen to connect.
[15] Fix | Delete
*
[16] Fix | Delete
* @package PemFTP
[17] Fix | Delete
* @subpackage Pure
[18] Fix | Delete
* @since 2.5.0
[19] Fix | Delete
*
[20] Fix | Delete
* @version 1.0
[21] Fix | Delete
* @copyright Alexey Dotsenko
[22] Fix | Delete
* @author Alexey Dotsenko
[23] Fix | Delete
* @link https://www.phpclasses.org/package/1743-PHP-FTP-client-in-pure-PHP.html
[24] Fix | Delete
* @license LGPL https://opensource.org/licenses/lgpl-license.html
[25] Fix | Delete
*/
[26] Fix | Delete
class ftp_pure extends ftp_base {
[27] Fix | Delete
[28] Fix | Delete
function __construct($verb=FALSE, $le=FALSE) {
[29] Fix | Delete
parent::__construct(false, $verb, $le);
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
// <!-- --------------------------------------------------------------------------------------- -->
[33] Fix | Delete
// <!-- Private functions -->
[34] Fix | Delete
// <!-- --------------------------------------------------------------------------------------- -->
[35] Fix | Delete
[36] Fix | Delete
function _settimeout($sock) {
[37] Fix | Delete
if(!@stream_set_timeout($sock, $this->_timeout)) {
[38] Fix | Delete
$this->PushError('_settimeout','socket set send timeout');
[39] Fix | Delete
$this->_quit();
[40] Fix | Delete
return FALSE;
[41] Fix | Delete
}
[42] Fix | Delete
return TRUE;
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
function _connect($host, $port) {
[46] Fix | Delete
$this->SendMSG("Creating socket");
[47] Fix | Delete
$sock = @fsockopen($host, $port, $errno, $errstr, $this->_timeout);
[48] Fix | Delete
if (!$sock) {
[49] Fix | Delete
$this->PushError('_connect','socket connect failed', $errstr." (".$errno.")");
[50] Fix | Delete
return FALSE;
[51] Fix | Delete
}
[52] Fix | Delete
$this->_connected=true;
[53] Fix | Delete
return $sock;
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
function _readmsg($fnction="_readmsg"){
[57] Fix | Delete
if(!$this->_connected) {
[58] Fix | Delete
$this->PushError($fnction, 'Connect first');
[59] Fix | Delete
return FALSE;
[60] Fix | Delete
}
[61] Fix | Delete
$result=true;
[62] Fix | Delete
$this->_message="";
[63] Fix | Delete
$this->_code=0;
[64] Fix | Delete
$go=true;
[65] Fix | Delete
do {
[66] Fix | Delete
$tmp=@fgets($this->_ftp_control_sock, 512);
[67] Fix | Delete
if($tmp===false) {
[68] Fix | Delete
$go=$result=false;
[69] Fix | Delete
$this->PushError($fnction,'Read failed');
[70] Fix | Delete
} else {
[71] Fix | Delete
$this->_message.=$tmp;
[72] Fix | Delete
if(preg_match("/^([0-9]{3})(-(.*[".CRLF."]{1,2})+\\1)? [^".CRLF."]+[".CRLF."]{1,2}$/", $this->_message, $regs)) $go=false;
[73] Fix | Delete
}
[74] Fix | Delete
} while($go);
[75] Fix | Delete
if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
[76] Fix | Delete
$this->_code=(int)$regs[1];
[77] Fix | Delete
return $result;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
function _exec($cmd, $fnction="_exec") {
[81] Fix | Delete
if(!$this->_ready) {
[82] Fix | Delete
$this->PushError($fnction,'Connect first');
[83] Fix | Delete
return FALSE;
[84] Fix | Delete
}
[85] Fix | Delete
if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
[86] Fix | Delete
$status=@fputs($this->_ftp_control_sock, $cmd.CRLF);
[87] Fix | Delete
if($status===false) {
[88] Fix | Delete
$this->PushError($fnction,'socket write failed');
[89] Fix | Delete
return FALSE;
[90] Fix | Delete
}
[91] Fix | Delete
$this->_lastaction=time();
[92] Fix | Delete
if(!$this->_readmsg($fnction)) return FALSE;
[93] Fix | Delete
return TRUE;
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
function _data_prepare($mode=FTP_ASCII) {
[97] Fix | Delete
if(!$this->_settype($mode)) return FALSE;
[98] Fix | Delete
if($this->_passive) {
[99] Fix | Delete
if(!$this->_exec("PASV", "pasv")) {
[100] Fix | Delete
$this->_data_close();
[101] Fix | Delete
return FALSE;
[102] Fix | Delete
}
[103] Fix | Delete
if(!$this->_checkCode()) {
[104] Fix | Delete
$this->_data_close();
[105] Fix | Delete
return FALSE;
[106] Fix | Delete
}
[107] Fix | Delete
$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));
[108] Fix | Delete
$this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
[109] Fix | Delete
$this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
[110] Fix | Delete
$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
[111] Fix | Delete
$this->_ftp_data_sock=@fsockopen($this->_datahost, $this->_dataport, $errno, $errstr, $this->_timeout);
[112] Fix | Delete
if(!$this->_ftp_data_sock) {
[113] Fix | Delete
$this->PushError("_data_prepare","fsockopen fails", $errstr." (".$errno.")");
[114] Fix | Delete
$this->_data_close();
[115] Fix | Delete
return FALSE;
[116] Fix | Delete
}
[117] Fix | Delete
else $this->_ftp_data_sock;
[118] Fix | Delete
} else {
[119] Fix | Delete
$this->SendMSG("Only passive connections available!");
[120] Fix | Delete
return FALSE;
[121] Fix | Delete
}
[122] Fix | Delete
return TRUE;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
function _data_read($mode=FTP_ASCII, $fp=NULL) {
[126] Fix | Delete
if(is_resource($fp)) $out=0;
[127] Fix | Delete
else $out="";
[128] Fix | Delete
if(!$this->_passive) {
[129] Fix | Delete
$this->SendMSG("Only passive connections available!");
[130] Fix | Delete
return FALSE;
[131] Fix | Delete
}
[132] Fix | Delete
while (!feof($this->_ftp_data_sock)) {
[133] Fix | Delete
$block=fread($this->_ftp_data_sock, $this->_ftp_buff_size);
[134] Fix | Delete
if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_local], $block);
[135] Fix | Delete
if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
[136] Fix | Delete
else $out.=$block;
[137] Fix | Delete
}
[138] Fix | Delete
return $out;
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
function _data_write($mode=FTP_ASCII, $fp=NULL) {
[142] Fix | Delete
if(is_resource($fp)) $out=0;
[143] Fix | Delete
else $out="";
[144] Fix | Delete
if(!$this->_passive) {
[145] Fix | Delete
$this->SendMSG("Only passive connections available!");
[146] Fix | Delete
return FALSE;
[147] Fix | Delete
}
[148] Fix | Delete
if(is_resource($fp)) {
[149] Fix | Delete
while(!feof($fp)) {
[150] Fix | Delete
$block=fread($fp, $this->_ftp_buff_size);
[151] Fix | Delete
if(!$this->_data_write_block($mode, $block)) return false;
[152] Fix | Delete
}
[153] Fix | Delete
} elseif(!$this->_data_write_block($mode, $fp)) return false;
[154] Fix | Delete
return TRUE;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
function _data_write_block($mode, $block) {
[158] Fix | Delete
if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_remote], $block);
[159] Fix | Delete
do {
[160] Fix | Delete
if(($t=@fwrite($this->_ftp_data_sock, $block))===FALSE) {
[161] Fix | Delete
$this->PushError("_data_write","Can't write to socket");
[162] Fix | Delete
return FALSE;
[163] Fix | Delete
}
[164] Fix | Delete
$block=substr($block, $t);
[165] Fix | Delete
} while(!empty($block));
[166] Fix | Delete
return true;
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
function _data_close() {
[170] Fix | Delete
@fclose($this->_ftp_data_sock);
[171] Fix | Delete
$this->SendMSG("Disconnected data from remote host");
[172] Fix | Delete
return TRUE;
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
function _quit($force=FALSE) {
[176] Fix | Delete
if($this->_connected or $force) {
[177] Fix | Delete
@fclose($this->_ftp_control_sock);
[178] Fix | Delete
$this->_connected=false;
[179] Fix | Delete
$this->SendMSG("Socket closed");
[180] Fix | Delete
}
[181] Fix | Delete
}
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
?>
[185] Fix | Delete
[186] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function