PHP 8.2.31
Preview: class-ftp-sockets.php Size: 8.28 KB
/home/nshryvcy/radiantskinclinics.org/wp-admin/includes/class-ftp-sockets.php

<?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");
		}
	}
}
?>

Directory Contents

Dirs: 1 × Files: 107

Name Size Perms Modified Actions
html-api DIR
- drwxr-xr-x 2026-04-30 05:16:59
Edit Download
7.85 KB lrw-r--r-- 2026-03-09 03:49:38
Edit Download
3.54 KB lrw-r--r-- 2023-07-11 09:03:24
Edit Download
149.19 KB lrw-r--r-- 2026-03-10 15:43:18
Edit Download
11.40 KB lrw-r--r-- 2026-03-14 02:44:48
Edit Download
3.58 KB lrw-r--r-- 2023-06-22 18:36:26
Edit Download
2.53 KB lrw-r--r-- 2024-05-02 21:20:10
Edit Download
2.60 KB lrw-r--r-- 2024-05-02 21:20:10
Edit Download
6.50 KB lrw-r--r-- 2026-01-05 21:04:58
Edit Download
14.84 KB lrw-r--r-- 2026-02-13 23:34:42
Edit Download
21.20 KB lrw-r--r-- 2026-05-13 11:20:44
Edit Download
48.03 KB lrw-r--r-- 2026-05-13 11:20:44
Edit Download
4.07 KB lrw-r--r-- 2024-03-07 10:58:16
Edit Download
5.30 KB lrw-r--r-- 2019-11-01 18:57:02
Edit Download
8.28 KB lrw-r--r-- 2022-03-22 20:25:04
Edit Download
26.70 KB lrw-r--r-- 2026-03-19 13:31:50
Edit Download
2.80 KB lrw-r--r-- 2024-05-02 21:20:10
Edit Download
15.16 KB lrw-r--r-- 2026-01-09 07:48:52
Edit Download
192.08 KB lrw-r--r-- 2024-12-13 03:23:16
Edit Download
11.67 KB lrw-r--r-- 2026-01-09 07:48:52
Edit Download
3.20 KB lrw-r--r-- 2023-06-14 10:34:28
Edit Download
22.70 KB lrw-r--r-- 2026-01-09 07:48:52
Edit Download
12.67 KB lrw-r--r-- 2026-01-09 07:48:52
Edit Download
4.08 KB lrw-r--r-- 2024-02-27 01:35:08
Edit Download
26.16 KB lrw-r--r-- 2026-02-13 23:34:42
Edit Download
4.97 KB lrw-r--r-- 2026-01-19 22:00:58
Edit Download
5.65 KB lrw-r--r-- 2026-03-10 16:34:44
Edit Download
13.96 KB lrw-r--r-- 2026-03-10 16:34:44
Edit Download
4.09 KB lrw-r--r-- 2023-06-22 18:36:26
Edit Download
6.79 KB lrw-r--r-- 2024-02-17 02:47:12
Edit Download
60.45 KB lrw-r--r-- 2025-06-03 20:51:34
Edit Download
33.80 KB lrw-r--r-- 2026-05-08 06:21:42
Edit Download
18.21 KB lrw-r--r-- 2026-01-09 09:22:50
Edit Download
70.27 KB lrw-r--r-- 2026-02-17 11:05:42
Edit Download
23.84 KB lrw-r--r-- 2024-02-17 02:47:12
Edit Download
18.17 KB lrw-r--r-- 2026-02-09 21:54:42
Edit Download
22.73 KB lrw-r--r-- 2025-11-27 02:52:32
Edit Download
18.06 KB lrw-r--r-- 2025-11-27 02:52:32
Edit Download
22.84 KB lrw-r--r-- 2026-02-20 07:25:46
Edit Download
7.64 KB lrw-r--r-- 2026-02-17 11:05:42
Edit Download
4.49 KB lrw-r--r-- 2026-01-05 21:04:58
Edit Download
9.29 KB lrw-r--r-- 2026-02-17 11:05:42
Edit Download
1.46 KB lrw-r--r-- 2020-11-14 21:54:08
Edit Download
51.84 KB lrw-r--r-- 2026-02-17 11:05:42
Edit Download
26.40 KB lrw-r--r-- 2026-03-03 12:18:44
Edit Download
22.23 KB lrw-r--r-- 2026-02-20 04:52:14
Edit Download
29.52 KB lrw-r--r-- 2026-02-23 11:06:42
Edit Download
15.32 KB lrw-r--r-- 2026-01-06 10:57:56
Edit Download
24.39 KB lrw-r--r-- 2026-01-13 02:17:00
Edit Download
56.75 KB lrw-r--r-- 2026-02-19 17:44:52
Edit Download
1.42 KB lrw-r--r-- 2022-10-04 07:47:16
Edit Download
63.46 KB lrw-r--r-- 2026-05-13 11:20:44
Edit Download
5.43 KB lrw-r--r-- 2022-03-11 00:22:02
Edit Download
5.58 KB lrw-r--r-- 2023-09-08 13:32:24
Edit Download
31.90 KB lrw-r--r-- 2025-08-27 14:34:28
Edit Download
14.44 KB lrw-r--r-- 2025-10-03 01:48:36
Edit Download
36.56 KB lrw-r--r-- 2026-04-27 06:20:42
Edit Download
14.00 KB lrw-r--r-- 2024-11-04 20:25:18
Edit Download
128.17 KB lrw-r--r-- 2026-02-21 02:13:48
Edit Download
6.26 KB lrw-r--r-- 2024-03-03 01:15:14
Edit Download
20.58 KB lrw-r--r-- 2026-02-26 03:52:44
Edit Download
15.33 KB lrw-r--r-- 2026-05-13 11:20:44
Edit Download
10.10 KB lrw-r--r-- 2026-01-09 09:22:50
Edit Download
6.90 KB lrw-r--r-- 2026-01-05 21:04:58
Edit Download
1.44 KB lrw-r--r-- 2019-10-08 21:19:04
Edit Download
47.23 KB lrw-r--r-- 2025-12-24 22:08:34
Edit Download
18.56 KB lrw-r--r-- 2026-01-06 10:57:56
Edit Download
6.08 KB lrw-r--r-- 2025-10-31 22:57:30
Edit Download
20.06 KB lrw-r--r-- 2022-09-20 03:24:12
Edit Download
5.70 KB lrw-r--r-- 2026-01-09 09:22:50
Edit Download
68.73 KB lrw-r--r-- 2026-05-08 06:21:42
Edit Download
40.77 KB lrw-r--r-- 2026-01-05 21:04:58
Edit Download
1.44 KB lrw-r--r-- 2021-12-07 17:20:02
Edit Download
285 B lrw-r--r-- 2026-05-26 18:13:28
Edit Download
25.37 KB lrw-r--r-- 2025-12-24 11:48:32
Edit Download
95.62 KB lrw-r--r-- 2026-03-12 01:01:46
Edit Download
42.96 KB lrw-r--r-- 2026-05-07 08:49:44
Edit Download
44.11 KB lrw-r--r-- 2026-03-14 20:00:54
Edit Download
6.46 KB lrw-r--r-- 2024-07-27 04:27:16
Edit Download
3.71 KB lrw-r--r-- 2022-10-04 07:47:16
Edit Download
117.12 KB lrw-r--r-- 2026-03-05 15:18:46
Edit Download
9.41 KB lrw-r--r-- 2026-03-06 02:08:44
Edit Download
65.29 KB lrw-r--r-- 2026-05-13 11:20:44
Edit Download
45.35 KB lrw-r--r-- 2026-05-08 19:59:44
Edit Download
1.27 KB lrw-r--r-- 2022-09-20 06:51:10
Edit Download
3.68 KB lrw-r--r-- 2022-09-20 06:51:10
Edit Download
33.45 KB lrw-r--r-- 2026-03-21 02:37:00
Edit Download
47.98 KB lrw-r--r-- 2026-03-24 09:58:00
Edit Download
26.40 KB lrw-r--r-- 2026-02-27 03:57:34
Edit Download
1.12 KB lrw-r--r-- 2023-09-21 05:27:26
Edit Download
4.14 KB lrw-r--r-- 2026-01-05 21:04:58
Edit Download
38.13 KB lrw-r--r-- 2026-01-09 09:22:50
Edit Download
91.09 KB lrw-r--r-- 2026-02-23 10:34:46
Edit Download
80.33 KB lrw-r--r-- 2026-05-13 11:20:44
Edit Download
32.66 KB lrw-r--r-- 2025-12-26 18:16:34
Edit Download
16.24 KB lrw-r--r-- 2026-04-28 15:23:44
Edit Download
44.51 KB lrw-r--r-- 2026-05-08 19:59:44
Edit Download
6.24 KB lrw-r--r-- 2026-01-15 05:00:00
Edit Download
8.28 KB lrw-r--r-- 2025-11-25 06:34:30
Edit Download
97.35 KB lrw-r--r-- 2026-02-19 14:43:48
Edit Download
6.83 KB lrw-r--r-- 2024-02-27 01:35:08
Edit Download
46.42 KB lrw-r--r-- 2026-02-23 10:34:46
Edit Download
10.82 KB lrw-r--r-- 2024-09-11 16:08:20
Edit Download
71.07 KB lrw-r--r-- 2026-05-19 21:16:42
Edit Download
34.03 KB lrw-r--r-- 2026-02-07 11:06:44
Edit Download
113.96 KB lrw-r--r-- 2026-02-15 13:02:42
Edit Download
23.39 KB lrw-r--r-- 2026-03-24 06:19:56
Edit Download
10.30 KB lrw-r--r-- 2026-02-19 03:03:44
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).