Tuns passive mode on or off.

@param bool $pasv The passive mode.
@return FTPClient Returns this FTP client.
@throws FTPException Throws a FTP exception if an I/O error occurs.
1304
public function pasv($pasv) {
        if (false === @ftp_pasv($this->getConnection(), $pasv)) {
            throw $this->newFTPException(sprintf("pasv from %d to %d failed", !$pasv, $pasv));
        }
        return $this;
    }
1213121
public function passive(bool $passive)
    {
        if (!@ftp_pasv($this->ftp, $passive)) {
            throw new Exception(sprintf("Cannot switch to passive = %s", $passive ? "true" : "false"));
        }

        return $this;
    }
866455
public static function getRemoteClient(array $params)
    {
        return new m62Ftp([
            'host' => $params['ftp_hostname'],
            'username' => $params['ftp_username'],
            'password' => $params['ftp_password'],
            'port' => $params['ftp_port'],
            'passive' => (isset($params['ftp_passive']) ? $params['ftp_passive'] : '0'),
            'ssl' => (! empty($params['ftp_ssl']) ? $params['ftp_ssl'] : '0'),
            'timeout' => (! empty($params['ftp_timeout']) ? $params['ftp_timeout'] : '30')
        ]);
    }
287563
public function setSerial($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->serial !== $v) {
            $this->serial = $v;
            $this->modifiedColumns[] = LicensePeer::SERIAL;
        }


        return $this;
    }
1219177
public function setPassive(/* boolean */ $passive) {
		// Close connection before changing password.
		if ($this->passive !== $passive) {
			$this->passive = $passive;
			if (isset($this->handle) && $this->handle != null) {
				$this->pasv($this->passive);
			}
		}
	}
1311715
public function beforeHandleTask($argv)
    {
        return function(Event $event, Console $console, Dispatcher $dispatcher) use ($argv) {
            //parse parameters
            $parsedOptions = OptionParser::parse($argv);

            $dispatcher->setParams(array(
                'activeTask'  => isset($parsedOptions[0]) ? $parsedOptions[0] : false,
                'activeAction'  => isset($parsedOptions[1]) ? $parsedOptions[1] : false,
                'args'    =>  count($parsedOptions) > 2 ? array_slice($parsedOptions, 2) : []
            ));
        };
    }
731882
private function connect()
    {
        if ($this->ssl && !function_exists('ftp_ssl_connect')) {
            throw new \RuntimeException('This Server Has No SSL-FTP Available.');
        }

        // open ftp connection
        if (!$this->ssl) {
            $this->connection = ftp_connect($this->host, $this->port, $this->timeout);
        } else {
            $this->connection = ftp_ssl_connect($this->host, $this->port, $this->timeout);
        }

        if (!$this->connection) {
            throw new \RuntimeException(sprintf('Could not connect to \'%s\' (port: %s).', $this->host, $this->port));
        }

        if (defined('FTP_USEPASVADDRESS')) {
            ftp_set_option($this->connection, FTP_USEPASVADDRESS, false);
        }

        $username = $this->username ?: 'anonymous';
        $password = $this->password ?: '';

        // login ftp user
        if (!@ftp_login($this->connection, $username, $password)) {
            $this->close();
            throw new \RuntimeException(sprintf('Could not login as %s.', $username));
        }

        // switch to passive mode if needed
        if ($this->passive && !ftp_pasv($this->connection, true)) {
            $this->close();
            throw new \RuntimeException('Could not turn passive mode on.');
        }

        // enable utf8 mode if configured
        if($this->utf8 == true) {
            ftp_raw($this->connection, "OPTS UTF8 ON");
        }

        // ensure the adapter's directory exists
        if ('/' !== $this->directory) {
            try {
                $this->ensureDirectoryExists($this->directory, $this->create);
            } catch (\RuntimeException $e) {
                $this->close();
                throw $e;
            }

            // change the current directory for the adapter's directory
            if (!ftp_chdir($this->connection, $this->directory)) {
                $this->close();
                throw new \RuntimeException(sprintf('Could not change current directory for the \'%s\' directory.', $this->directory));
            }
        }
    }
148857
public function onWriteEv($bev)
    {
        $this->writing = false;
        if ($this->finished) {
            if ($this->bev->output->length === 0) {
                $this->close();
            }
            return;
        }
        if (!$this->ready) {
            $this->ready = true;
            while (!$this->onWriteOnce->isEmpty()) {
                try {
                    $this->onWriteOnce->executeOne($this);
                } catch (\Exception $e) {
                    Daemon::uncaughtExceptionHandler($e);
                }
                if (!$this->ready) {
                    return;
                }
            }
            $this->alive = true;
            try {
                $this->onReady();
                if ($this->wRead) {
                    $this->wRead = false;
                    $this->onRead();
                }
            } catch (\Exception $e) {
                Daemon::uncaughtExceptionHandler($e);
            }
        } else {
            $this->onWriteOnce->executeAll($this);
        }
        try {
            $this->onWrite();
        } catch (\Exception $e) {
            Daemon::uncaughtExceptionHandler($e);
        }
    }
743188
public function setReceiverlogin($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->receiverlogin !== $v) {
            $this->receiverlogin = $v;
            $this->modifiedColumns[GamecurrencyTableMap::COL_RECEIVERLOGIN] = true;
        }

        return $this;
    }
1217479
public function write($remote, $buffer)
	{
		// Determine file type
		$mode = $this->_findMode($remote);

		// If native FTP support is enabled let's use it...
		if (FTP_NATIVE)
		{
			// Turn passive mode on
			if (@ftp_pasv($this->conn, true) === false)
			{
				throw new FilesystemException(__METHOD__ . ': Unable to use passive mode.');
			}

			$tmp = fopen('buffer://tmp', 'br+');
			fwrite($tmp, $buffer);
			rewind($tmp);

			if (@ftp_fput($this->conn, $remote, $tmp, $mode) === false)
			{
				fclose($tmp);

				throw new FilesystemException(__METHOD__ . 'Bad response.');
			}

			fclose($tmp);

			return true;
		}

		// First we need to set the transfer mode
		$this->_mode($mode);

		// Start passive mode
		if (!$this->_passive())
		{
			throw new FilesystemException(__METHOD__ . ': Unable to use passive mode.');
		}

		// Send store command to the FTP server
		if (!$this->_putCmd('STOR ' . $remote, array(150, 125)))
		{
			@ fclose($this->dataconn);

			throw new FilesystemException(
				sprintf('%1$s: Bad response.  Server response: %2$s [Expected: 150 or 125].  Path sent: %3$s', __METHOD__, $this->response, $remote)
			);
		}

		// Write buffer to the data connection port
		do
		{
			if (($result = @ fwrite($this->dataconn, $buffer)) === false)
			{
				throw new FilesystemException(__METHOD__ . ': Unable to write to data port socket.');
			}

			$buffer = substr($buffer, $result);
		}
		while ($buffer != '');

		// Close the data connection port [Data transfer complete]
		fclose($this->dataconn);

		// Verify that the server recieved the transfer
		if (!$this->_verifyResponse(226))
		{
			throw new FilesystemException(
				sprintf('%1$s: Transfer failed.  Server response: %2$s [Expected: 226].  Path sent: %3$s', __METHOD__, $this->response, $remote)
			);
		}

		return true;
	}
32605
public function setPublicKey($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->public_key !== $v) {
            $this->public_key = $v;
            $this->modifiedColumns[] = RemoteAppPeer::PUBLIC_KEY;
        }


        return $this;
    }
1151924
public function connect()
    {
        $this->connection = ftp_connect($this->host);
        if (ftp_login($this->connection, $this->username, $this->password)) {
            if (ftp_chdir($this->connection, $this->getChdir()) && ftp_pasv($this->connection, $this->passive)) {
                $this->connected = true;
                return true;
            }
        }
        return false;
    }
230463
protected function recv(bool $defer = false, bool $release = true)
    {
        if ($this->connection instanceof ConnectionInterface) {
            try {
                $result = $this->connection->receive();
            } catch (\Throwable $throwable) {
                throw $throwable;
            } finally {
                $this->release($release);
            }

            return $result;
        }

        try {
            $result = $this->connection->recv();
        } catch (\Throwable $throwable) {
            throw $throwable;
        } finally {
            if ($defer) {
                $this->connection->setDefer(false);
            }
        }

        return $result;
    }
440633
public function getRequestServer($port = false, $protocol = false)
    {
        $servername = $this->getServerName();

        if ($port && $this->server('SERVER_PORT' !== false)) {
            $servername .= ':' . $this->server('SERVER_PORT');
        }

        if ($protocol) {
            $servername = (
                ($this->server('HTTPS') !== 'off'
                    || $this->server('SERVER_PORT') == 443) ? "https://" : "http://") . $servername
            ;
        }

        return $servername;
    }
1236777
public function setOption($level, $optname, $optval)
    {
        $ret = @socket_set_option($this->resource, $level, $optname, $optval);
        if ($ret === false) {
            throw Exception::createFromSocketResource($this->resource);
        }
        return $this;
    }
1014840
public function connect()
        {
            // check if non-SSL connection
            if(!static::$ssl) {
                // attempt connection
                if(!static::$_stream = ftp_connect(static::$_host, static::$_port, static::$_timeout)) {
                    // set last error
                    static::$error = "Failed to connect to {static::$_host}";
                    return false;
                }
            // SSL connection
            } elseif(function_exists("ftp_ssl_connect")) {
                // attempt SSL connection
                if(!static::$_stream = ftp_ssl_connect(static::$_host, static::$_port, static::$_timeout)) {
                    // set last error
                    static::$error = "Failed to connect to {static::$_host} (SSL connection)";
                    return false;
                }
            // invalid connection type
            } else {
                static::$error = "Failed to connect to {static::$_host} (invalid connection type)";
                return false;
            }

            // attempt login
            if(ftp_login(static::$_stream, static::$_user, static::$_pwd)) {
                // set passive mode
                ftp_pasv(static::$_stream, (bool)static::$passive);

                // set system type
                static::$systemType = ftp_systype(static::$_stream);

                // connection successful
                return true;
            // login failed
            } else {
                static::$error = "Failed to connect to {static::$_host} (login failed)";
                return false;
            }
        }
1162684
function connect($clean = true)
    {

        // Don't do anything, if server address is not set
        if(!$this->serverAddress) {
            return false;
        }

        // Is encryption enabled?
        if($this->connMethod!="tcp") {
            $socketContextOptions = [ "ssl" => [] ];
            $socketContextOptions["ssl"]["verify_peer_name"] = $this->verifyPeerName;

            if($this->caFile) {
                $socketContextOptions["ssl"]["cafile"]=$this->caFile;
            }

            if($this->clientCrt) {
                $socketContextOptions["ssl"]["local_cert"]=$this->clientCrt;
            }

            if ($this->clientCrt && $this->clientKey) {
                $socketContextOptions["ssl"]["local_pk"]=$this->clientKey;
            }

            $socketContext = stream_context_create($socketContextOptions);
            $host = $this->connMethod . "://" . $this->serverAddress . ":" . $this->serverPort;

            $this->socket = stream_socket_client(
                $host, $errno, $errstr, 60, STREAM_CLIENT_CONNECT, $socketContext);

            $this->debugMessage("Connecting to: ".$host);
        } else {
            $host = $this->connMethod . "://" . $this->serverAddress . ":" . $this->serverPort;
            $this->socket = stream_socket_client(
                $host, $errno, $errstr, 60, STREAM_CLIENT_CONNECT );
            $this->debugMessage("Connecting to: ".$host);
        }

        //
        if(!$this->socket) {
            $this->socket = null;
            $this->debugMessage("Connection failed.. $errno , $errstr");
            return false;
        }

        //
        stream_set_timeout($this->socket, 10);
        stream_set_blocking($this->socket, false);

        $bytes = 0;
        $buffer = "";

        // ------------------------------------
        // Calculate connect flags

        $var = $clean?2:0;
/*
        if($this->will != NULL)
        {
            $var += 4;                              // Set will flag
            $var += ($this->will['qos'] << 3);      // Set will qos

            if($this->will['retain'])
                $var += 32;                     // Set will retain
        }
*/

        if($this->authPass != NULL) {
            $var += 64;
        }

        if($this->authUser != NULL) {
            $var += 128;
        }

        // ------------------------------------
        // Create CONNECT packet (for MQTT 3.1.1 protocol)

        $buffer .= $this->convertString("MQTT", $bytes);

        $buffer .= chr(0x04);   // Protocol level
        $bytes++;

        $buffer .= chr($var);   // Connect flags
        $bytes++;

        $buffer .= chr($this->keepAlive >> 8);  // Keepalive (MSB)
        $bytes++;

        $buffer .= chr($this->keepAlive & 0xff);    // Keepalive (LSB)
        $bytes++;

        $buffer .= $this->convertString($this->clientID,$bytes);

        //Adding will to payload
        /*
        if($this->will != NULL){
            $buffer .= $this->strwritestring($this->will['topic'],$bytes);
            $buffer .= $this->strwritestring($this->will['content'],$bytes);
        }
        */

        if($this->authUser) {
            $buffer .= $this->convertString($this->authUser,$bytes);
        }

        if($this->authPass) {
            $buffer .= $this->convertString($this->authPass,$bytes);
        }

        $header = $this->createHeader( 0x10 , $bytes );
        fwrite($this->socket, $header, strlen($header));
        fwrite($this->socket, $buffer);

        // Wait for CONNACK packet
        $string = $this->readBytes(4, false);
        if(strlen($string)!=4) {
            $this->debugMessage("Connection failed! Server gave unexpected response (".strlen($string)." bytes).");
            return false;
        }

        if(ord($string{0}) == 0x20 && $string{3} == chr(0)) {
            $this->debugMessage("Connected to MQTT");
        } else {
            $msg = sprintf("Connection failed! Error: 0x%02x 0x%02x",
                ord($string{0}),ord($string{3}) );
            $this->debugMessage($msg);
            return false;
        }

        $this->timeSincePingReq = time();
        $this->timeSincePingResp = time();

        return true;
    }