Mercurial > hg > isophonics-drupal-site
diff core/lib/Drupal/Core/FileTransfer/FTP.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/lib/Drupal/Core/FileTransfer/FTP.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,49 @@ +<?php + +namespace Drupal\Core\FileTransfer; + +/** + * Defines the base class for FTP implementations. + */ +abstract class FTP extends FileTransfer { + + /** + * {@inheritdoc} + */ + public function __construct($jail, $username, $password, $hostname, $port) { + $this->username = $username; + $this->password = $password; + $this->hostname = $hostname; + $this->port = $port; + parent::__construct($jail); + } + + /** + * {@inheritdoc} + */ + public static function factory($jail, $settings) { + $username = empty($settings['username']) ? '' : $settings['username']; + $password = empty($settings['password']) ? '' : $settings['password']; + $hostname = empty($settings['advanced']['hostname']) ? 'localhost' : $settings['advanced']['hostname']; + $port = empty($settings['advanced']['port']) ? 21 : $settings['advanced']['port']; + + if (function_exists('ftp_connect')) { + $class = 'Drupal\Core\FileTransfer\FTPExtension'; + } + else { + throw new FileTransferException('No FTP backend available.'); + } + + return new $class($jail, $username, $password, $hostname, $port); + } + + /** + * {@inheritdoc} + */ + public function getSettingsForm() { + $form = parent::getSettingsForm(); + $form['advanced']['port']['#default_value'] = 21; + return $form; + } + +}