2 namespace wcf\system\io
;
3 use wcf\system\exception\SystemException
;
6 * The RemoteFile class opens a connection to a remote host as a file.
9 * @copyright 2001-2014 WoltLab GmbH
10 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
11 * @package com.woltlab.wcf
12 * @subpackage system.io
13 * @category Community Framework
15 class RemoteFile
extends File
{
32 protected $errorNumber = 0;
38 protected $errorDesc = '';
41 * Opens a new connection to a remote host.
44 * @param integer $port
45 * @param integer $timeout
46 * @param array $options
48 public function __construct($host, $port, $timeout = 30) {
52 $this->resource = @fsockopen
($host, $port, $this->errorNumber
, $this->errorDesc
, $timeout);
53 if ($this->resource === false) {
54 throw new SystemException('Can not connect to ' . $host, 0, $this->errorDesc
);
59 * Returns the error number of the last error.
63 public function getErrorNumber() {
64 return $this->errorNumber
;
68 * Returns the error description of the last error.
72 public function getErrorDesc() {
73 return $this->errorDesc
;
77 * Switches TLS support for this connection.
78 * Usually used in combination with 'STARTTLS'
80 * @param boolean $enable Whether TLS support should be enabled
81 * @return boolean True on success, false otherwise
83 public function setTLS($enable) {
84 if (!$this->hasTLSSupport()) return false;
86 return stream_socket_enable_crypto($this->resource, $enable, STREAM_CRYPTO_METHOD_TLS_CLIENT
);
90 * Returns whether TLS support is available.
94 public function hasTLSSupport() {
95 return function_exists('stream_socket_enable_crypto');