404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@13.58.199.20: ~ $
<?php

declare(strict_types=1);

namespace League\Flysystem\Ftp;

use const FTP_USEPASVADDRESS;

class FtpConnectionProvider implements ConnectionProvider
{
    /**
     * @return resource
     *
     * @throws FtpConnectionException
     */
    public function createConnection(FtpConnectionOptions $options)
    {
        $connection = $this->createConnectionResource(
            $options->host(),
            $options->port(),
            $options->timeout(),
            $options->ssl()
        );

        try {
            $this->authenticate($options, $connection);
            $this->enableUtf8Mode($options, $connection);
            $this->ignorePassiveAddress($options, $connection);
            $this->makeConnectionPassive($options, $connection);
        } catch (FtpConnectionException $exception) {
            ftp_close($connection);
            throw $exception;
        }

        return $connection;
    }

    /**
     * @return resource
     */
    private function createConnectionResource(string $host, int $port, int $timeout, bool $ssl)
    {
        $connection = $ssl ? @ftp_ssl_connect($host, $port, $timeout) : @ftp_connect($host, $port, $timeout);

        if ($connection === false) {
            throw UnableToConnectToFtpHost::forHost($host, $port, $ssl);
        }

        return $connection;
    }

    /**
     * @param resource $connection
     */
    private function authenticate(FtpConnectionOptions $options, $connection): void
    {
        if ( ! @ftp_login($connection, $options->username(), $options->password())) {
            throw new UnableToAuthenticate();
        }
    }

    /**
     * @param resource $connection
     */
    private function enableUtf8Mode(FtpConnectionOptions $options, $connection): void
    {
        if ( ! $options->utf8()) {
            return;
        }

        $response = @ftp_raw($connection, "OPTS UTF8 ON");

        if ( ! in_array(substr($response[0], 0, 3), ['200', '202'])) {
            throw new UnableToEnableUtf8Mode(
                'Could not set UTF-8 mode for connection: ' . $options->host() . '::' . $options->port()
            );
        }
    }

    /**
     * @param resource $connection
     */
    private function ignorePassiveAddress(FtpConnectionOptions $options, $connection): void
    {
        $ignorePassiveAddress = $options->ignorePassiveAddress();

        if ( ! is_bool($ignorePassiveAddress) || ! defined('FTP_USEPASVADDRESS')) {
            return;
        }

        if ( ! @ftp_set_option($connection, FTP_USEPASVADDRESS, ! $ignorePassiveAddress)) {
            throw UnableToSetFtpOption::whileSettingOption('FTP_USEPASVADDRESS');
        }
    }

    /**
     * @param resource $connection
     */
    private function makeConnectionPassive(FtpConnectionOptions $options, $connection): void
    {
        if ( ! @ftp_pasv($connection, $options->passive())) {
            throw new UnableToMakeConnectionPassive(
                'Could not set passive mode for connection: ' . $options->host() . '::' . $options->port()
            );
        }
    }
}

Filemanager

Name Type Size Permission Actions
.github Folder 0755
.gitattributes File 154 B 0644
ConnectionProvider.php File 221 B 0644
ConnectivityChecker.php File 216 B 0644
ConnectivityCheckerThatCanFail.php File 678 B 0644
FtpAdapter.php File 21.83 KB 0644
FtpAdapterTest.php File 2.85 KB 0644
FtpAdapterTestCase.php File 11.47 KB 0644
FtpConnectionException.php File 185 B 0644
FtpConnectionOptions.php File 3.01 KB 0644
FtpConnectionProvider.php File 3.11 KB 0644
FtpConnectionProviderTest.php File 5.67 KB 0644
FtpdAdapterTest.php File 761 B 0644
InvalidListResponseReceived.php File 237 B 0644
NoopCommandConnectivityChecker.php File 628 B 0644
NoopCommandConnectivityCheckerTest.php File 1.62 KB 0644
README.md File 289 B 0644
RawListFtpConnectivityChecker.php File 450 B 0644
RawListFtpConnectivityCheckerTest.php File 1.13 KB 0644
UnableToAuthenticate.php File 316 B 0644
UnableToConnectToFtpHost.php File 467 B 0644
UnableToEnableUtf8Mode.php File 198 B 0644
UnableToMakeConnectionPassive.php File 199 B 0644
UnableToResolveConnectionRoot.php File 955 B 0644
UnableToSetFtpOption.php File 368 B 0644
composer.json File 663 B 0644