var/www/html/servotec-doerpen/wp-admin/includes | uid:33
class-ftp-sockets.php [X]
<?php
/**
 * PemFTP - An Ftp implementation in pure PHP
 *
 * @package PemFTP
 * @since 2.5.0
 *
 * @version 1.0
 * @copyright Alexey Dotsenko
 * @author Alexey Dotsenko
 * @link https://www.phpclasses.org/package/1743-PHP-FTP-client-in-pure-PHP.html
 * @license LGPL https://opensource.org/licenses/lgpl-license.html
 */

/**
 * Socket Based FTP implementation
 *
 * @package PemFTP
 * @subpackage Socket
 * @since 2.5.0
 *
 * @version 1.0
 * @copyright Alexey Dotsenko
 * @author Alexey Dotsenko
 * @link https://www.phpclasses.org/package/1743-PHP-FTP-client-in-pure-PHP.html
 * @license LGPL https://opensource.org/licenses/lgpl-license.html
 */
class ftp_sockets extends ftp_base {

	function __construct($verb=FALSE, $le=FALSE) {
		parent::__construct(true, $verb, $le);
	}

// <!-- --------------------------------------------------------------------------------------- -->
// <!--       Private functions                                                                 -->
// <!-- --------------------------------------------------------------------------------------- -->

	function _settimeout($sock) {
		if(!@socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) {
			$this->PushError('_connect','socket set receive timeout',socket_strerror(socket_last_error($sock)));
			@socket_close($sock);
			return FALSE;
		}
		if(!@socket_set_option($sock, SOL_SOCKET , SO_SNDTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) {
			$this->PushError('_connect','socket set send timeout',socket_strerror(socket_last_error($sock)));
			@socket_close($sock);
			return FALSE;
		}
		return true;
	}

	function _connect($host, $port) {
		$this->SendMSG("Creating socket");
		if(!($sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
			$this->PushError('_connect','socket create failed',socket_strerror(socket_last_error($sock)));
			return FALSE;
		}
		if(!$this->_settimeout($sock)) return FALSE;
		$this->SendMSG("Connecting to \"".$host.":".$port."\"");
		if (!($res = @socket_connect($sock, $host, $port))) {
			$this->PushError('_connect','socket connect failed',socket_strerror(socket_last_error($sock)));
			@socket_close($sock);
			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=@socket_read($this->_ftp_control_sock, 4096, PHP_BINARY_READ);
			if($tmp===false) {
				$go=$result=false;
				$this->PushError($fnction,'Read failed', socket_strerror(socket_last_error($this->_ftp_control_sock)));
			} else {
				$this->_message.=$tmp;
				$go = !preg_match("/^([0-9]{3})(-.+\\1)? [^".CRLF."]+".CRLF."$/Us", $this->_message, $regs);
			}
		} 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=@socket_write($this->_ftp_control_sock, $cmd.CRLF);
		if($status===false) {
			$this->PushError($fnction,'socket write failed', socket_strerror(socket_last_error($this->stream)));
			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;
		$this->SendMSG("Creating data socket");
		$this->_ftp_data_sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
		if ($this->_ftp_data_sock < 0) {
			$this->PushError('_data_prepare','socket create failed',socket_strerror(socket_last_error($this->_ftp_data_sock)));
			return FALSE;
		}
		if(!$this->_settimeout($this->_ftp_data_sock)) {
			$this->_data_close();
			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(",", 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);
			if(!@socket_connect($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) {
				$this->PushError("_data_prepare","socket_connect", socket_strerror(socket_last_error($this->_ftp_data_sock)));
				$this->_data_close();
				return FALSE;
			}
			else $this->_ftp_temp_sock=$this->_ftp_data_sock;
		} else {
			if(!@socket_getsockname($this->_ftp_control_sock, $addr, $port)) {
				$this->PushError("_data_prepare","cannot get control socket information", socket_strerror(socket_last_error($this->_ftp_control_sock)));
				$this->_data_close();
				return FALSE;
			}
			if(!@socket_bind($this->_ftp_data_sock,$addr)){
				$this->PushError("_data_prepare","cannot bind data socket", socket_strerror(socket_last_error($this->_ftp_data_sock)));
				$this->_data_close();
				return FALSE;
			}
			if(!@socket_listen($this->_ftp_data_sock)) {
				$this->PushError("_data_prepare","cannot listen data socket", socket_strerror(socket_last_error($this->_ftp_data_sock)));
				$this->_data_close();
				return FALSE;
			}
			if(!@socket_getsockname($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) {
				$this->PushError("_data_prepare","cannot get data socket information", socket_strerror(socket_last_error($this->_ftp_data_sock)));
				$this->_data_close();
				return FALSE;
			}
			if(!$this->_exec('PORT '.str_replace('.',',',$this->_datahost.'.'.($this->_dataport>>8).'.'.($this->_dataport&0x00FF)), "_port")) {
				$this->_data_close();
				return FALSE;
			}
			if(!$this->_checkCode()) {
				$this->_data_close();
				return FALSE;
			}
		}
		return TRUE;
	}

	function _data_read($mode=FTP_ASCII, $fp=NULL) {
		$NewLine=$this->_eol_code[$this->OS_local];
		if(is_resource($fp)) $out=0;
		else $out="";
		if(!$this->_passive) {
			$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
			$this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock);
			if($this->_ftp_temp_sock===FALSE) {
				$this->PushError("_data_read","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
				$this->_data_close();
				return FALSE;
			}
		}

		while(($block=@socket_read($this->_ftp_temp_sock, $this->_ftp_buff_size, PHP_BINARY_READ))!==false) {
			if($block==="") break;
			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;
		}
		return $out;
	}

	function _data_write($mode=FTP_ASCII, $fp=NULL) {
		$NewLine=$this->_eol_code[$this->OS_local];
		if(is_resource($fp)) $out=0;
		else $out="";
		if(!$this->_passive) {
			$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
			$this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock);
			if($this->_ftp_temp_sock===FALSE) {
				$this->PushError("_data_write","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
				$this->_data_close();
				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;
			}
		} elseif(!$this->_data_write_block($mode, $fp)) return false;
		return true;
	}

	function _data_write_block($mode, $block) {
		if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_remote], $block);
		do {
			if(($t=@socket_write($this->_ftp_temp_sock, $block))===FALSE) {
				$this->PushError("_data_write","socket_write", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
				$this->_data_close();
				return FALSE;
			}
			$block=substr($block, $t);
		} while(!empty($block));
		return true;
	}

	function _data_close() {
		@socket_close($this->_ftp_temp_sock);
		@socket_close($this->_ftp_data_sock);
		$this->SendMSG("Disconnected data from remote host");
		return TRUE;
	}

	function _quit() {
		if($this->_connected) {
			@socket_close($this->_ftp_control_sock);
			$this->_connected=false;
			$this->SendMSG("Socket closed");
		}
	}
}
?>
admin-filters.php7.8KV E R D
admin.php3.5KV E R D
bookmark.php11.4KV E R D
class-automatic-upgrader-skin.php3.6KV E R D
class-bulk-plugin-upgrader-skin.php2.5KV E R D
class-bulk-theme-upgrader-skin.php2.6KV E R D
class-bulk-upgrader-skin.php6.5KV E R D
class-core-upgrader.php14.8KV E R D
class-custom-background.php21.2KV E R D
class-custom-image-header.php48KV E R D
class-file-upload-upgrader.php4.1KV E R D
class-ftp-pure.php5.3KV E R D
class-ftp-sockets.php8.3KV E R D
class-language-pack-upgrader-skin.php2.8KV E R D
class-language-pack-upgrader.php15.2KV E R D
class-pclzip.php192.1KV E R D
class-plugin-installer-skin.php11.7KV E R D
class-plugin-upgrader-skin.php3.2KV E R D
class-plugin-upgrader.php22.7KV E R D
class-theme-installer-skin.php12.7KV E R D
class-theme-upgrader-skin.php4.1KV E R D
class-theme-upgrader.php26.2KV E R D
class-walker-category-checklist.php5KV E R D
class-walker-nav-menu-checklist.php5.6KV E R D
class-walker-nav-menu-edit.php14KV E R D
class-wp-ajax-upgrader-skin.php4.1KV E R D
class-wp-application-passwords-list-table.php6.8KV E R D
class-wp-automatic-updater.php60.5KV E R D
class-wp-comments-list-table.php33.8KV E R D
class-wp-community-events.php18.2KV E R D
class-wp-debug-data.php70.3KV E R D
class-wp-filesystem-base.php23.8KV E R D
class-wp-filesystem-direct.php18.2KV E R D
class-wp-filesystem-ftpext.php22.7KV E R D
class-wp-filesystem-ftpsockets.php18.1KV E R D
class-wp-filesystem-ssh2.php22.8KV E R D
class-wp-internal-pointers.php4.5KV E R D
class-wp-links-list-table.php9.3KV E R D
class-wp-list-table-compat.php1.5KV E R D
class-wp-list-table.php51.9KV E R D
class-wp-media-list-table.php26.4KV E R D
class-wp-ms-sites-list-table.php22.2KV E R D
class-wp-ms-themes-list-table.php29.5KV E R D
class-wp-ms-users-list-table.php15.3KV E R D
class-wp-plugin-install-list-table.php24.4KV E R D
class-wp-plugins-list-table.php56.7KV E R D
class-wp-post-comments-list-table.php1.4KV E R D
class-wp-posts-list-table.php63.5KV E R D
class-wp-privacy-data-export-requests-list-table.php5.4KV E R D
class-wp-privacy-data-removal-requests-list-table.php5.6KV E R D
class-wp-privacy-policy-content.php31.9KV E R D
class-wp-privacy-requests-table.php14.4KV E R D
class-wp-screen.php36.6KV E R D
class-wp-site-health-auto-updates.php14KV E R D
class-wp-site-health.php128.2KV E R D
class-wp-site-icon.php6.3KV E R D
class-wp-terms-list-table.php20.6KV E R D
class-wp-theme-install-list-table.php15.3KV E R D
class-wp-themes-list-table.php10.1KV E R D
class-wp-upgrader-skin.php6.9KV E R D
class-wp-upgrader-skins.php1.4KV E R D
class-wp-upgrader.php47.2KV E R D
class-wp-users-list-table.php18.6KV E R D
comment.php6.1KV E R D
continents-cities.php20.1KV E R D
credits.php5.7KV E R D
dashboard.php68.7KV E R D
edit-tag-messages.php1.4KV E R D
export.php25.4KV E R D
file.php95.6KV E R D
image-edit.php43KV E R D
image.php44.1KV E R D
import.php6.5KV E R D
list-table.php3.7KV E R D
media.php117.1KV E R D
menu.php9.4KV E R D
meta-boxes.php65.3KV E R D
misc.php45.4KV E R D
ms-admin-filters.php1.3KV E R D
ms-deprecated.php3.7KV E R D
ms.php33.4KV E R D
network.php26.4KV E R D
noop.php1.1KV E R D
options.php4.1KV E R D
plugin-install.php38.2KV E R D
post.php80.3KV E R D
privacy-tools.php32.7KV E R D
schema.php44.5KV E R D
screen.php6.2KV E R D
template.php97.3KV E R D
theme.php46.4KV E R D
translation-install.php10.8KV E R D
update-core.php71.2KV E R D
update.php34KV E R D
upgrade.php114KV E R D
user.php23.4KV E R D
widgets.php10.3KV E R D