Ftp.php in Flysystem 3.x
File
src/Flysystem/Ftp.php
View source
<?php
namespace Drupal\flysystem\Flysystem;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\flysystem\Flysystem\Adapter\MissingAdapter;
use Drupal\flysystem\Plugin\FlysystemPluginInterface;
use Drupal\flysystem\Plugin\FlysystemUrlTrait;
use League\Flysystem\Adapter\Ftp as FtpAdapter;
class Ftp implements FlysystemPluginInterface {
use FlysystemUrlTrait;
protected $configuration;
public function __construct(array $configuration) {
$this->configuration = $configuration;
if (empty($this->configuration['host'])) {
$this->configuration['host'] = '127.0.0.1';
}
}
public function getAdapter() {
try {
$adapter = new FtpAdapter($this->configuration);
$adapter
->connect();
} catch (\RuntimeException $e) {
$adapter = new MissingAdapter();
}
return $adapter;
}
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' => $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' => $this->configuration['port'] ?? 21,
],
],
];
}
}
Classes
Name |
Description |
Ftp |
Drupal plugin for the "FTP" Flysystem adapter. |