wppaste
WordPress

ftp_sockets

Since
2.5.0
Source
wp-admin/includes/class-ftp-sockets.php:28
Socket Based FTP implementation

Compatibility

WordPress
since 2.5.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Methods · 11

Source code

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;	}

Changelog

Introduced in 2.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-admin/includes/class-ftp-sockets.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.