You are here

class Ftp in Flysystem 7

Same name and namespace in other branches
  1. 8 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.

Hierarchy

Expanded class hierarchy of Ftp

File

src/Flysystem/Ftp.php, line 17
Contains \Drupal\flysystem\Flysystem\Ftp.

Namespace

Drupal\flysystem\Flysystem
View source
class Ftp extends FlysystemPluginBase {

  /**
   * 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 array();
    }
    return array(
      array(
        'severity' => WATCHDOG_ERROR,
        'message' => 'There was an error connecting to the FTP server %host:%port.',
        'context' => array(
          '%host' => $this->configuration['host'],
          '%port' => isset($this->configuration['port']) ? $this->configuration['port'] : 21,
        ),
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlysystemPluginBase::create public static function Creates a new plugin instance. Overrides FlysystemPluginInterface::create 1
FlysystemPluginBase::getExternalUrl public function Returns a web accessible URL for the resource. Overrides FlysystemPluginInterface::getExternalUrl 2
FlysystemPluginBase::getScheme protected function Returns the scheme from the internal URI.
FlysystemPluginBase::getTarget protected function Returns the target file path of a URI.
Ftp::$configuration protected property Plugin configuration.
Ftp::ensure public function
Ftp::getAdapter public function Returns the Flysystem adapter Overrides FlysystemPluginInterface::getAdapter
Ftp::__construct public function Constructs an Ftp object.