You are here

class Ftp in Flysystem 8

Same name and namespace in other branches
  1. 7 src/Flysystem/Ftp.php \Drupal\flysystem\Flysystem\Ftp
  2. 3.x src/Flysystem/Ftp.php \Drupal\flysystem\Flysystem\Ftp
  3. 2.0.x src/Flysystem/Ftp.php \Drupal\flysystem\Flysystem\Ftp
  4. 3.0.x src/Flysystem/Ftp.php \Drupal\flysystem\Flysystem\Ftp

Drupal plugin for the "FTP" Flysystem adapter.

Plugin annotation


@Adapter(
  id = "ftp",
  extensions = {"ftp"}
)

Hierarchy

Expanded class hierarchy of Ftp

1 file declares its use of Ftp
FtpTest.php in tests/src/Unit/Flysystem/FtpTest.php

File

src/Flysystem/Ftp.php, line 19

Namespace

Drupal\flysystem\Flysystem
View source
class Ftp implements FlysystemPluginInterface {
  use FlysystemUrlTrait;

  /**
   * Plugin configuration.
   *
   * @var array
   */
  protected $configuration;

  /**
   * Constructs an Ftp object.
   *
   * @param array $configuration
   *   Plugin configuration array.
   */
  public function __construct(array $configuration) {
    $this->configuration = $configuration;
    if (empty($this->configuration['host'])) {
      $this->configuration['host'] = '127.0.0.1';
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getAdapter() {
    try {
      $adapter = new FtpAdapter($this->configuration);
      $adapter
        ->connect();
    } catch (\RuntimeException $e) {

      // A problem connecting to the server.
      $adapter = new MissingAdapter();
    }
    return $adapter;
  }

  /**
   * {@inheritdoc}
   */
  public function ensure($force = FALSE) {
    if ($this
      ->getAdapter() instanceof FtpAdapter) {
      return [
        [
          'severity' => RfcLogLevel::INFO,
          'message' => 'Successfully connected to %host:%port.',
          'context' => [
            '%host' => $this->configuration['host'],
            '%port' => isset($this->configuration['port']) ? $this->configuration['port'] : 21,
          ],
        ],
      ];
    }
    return [
      [
        'severity' => RfcLogLevel::ERROR,
        'message' => 'There was an error connecting to the FTP server %host:%port.',
        'context' => [
          '%host' => $this->configuration['host'],
          '%port' => isset($this->configuration['port']) ? $this->configuration['port'] : 21,
        ],
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlysystemUrlTrait::getExternalUrl public function Returns a web accessible URL for the resource.
FlysystemUrlTrait::getScheme protected function Returns the scheme from the internal URI.
FlysystemUrlTrait::getTarget protected function Returns the target file path of a URI.
Ftp::$configuration protected property Plugin configuration.
Ftp::ensure public function Checks the sanity of the filesystem. Overrides FlysystemPluginInterface::ensure
Ftp::getAdapter public function Returns the Flysystem adapter. Overrides FlysystemPluginInterface::getAdapter
Ftp::__construct public function Constructs an Ftp object.