104 foreach ($this->configurable as $setting) {
105 if ( ! isset($config[$setting])) {
109 $method =
'set' . ucfirst($setting);
111 if (method_exists($this, $method)) {
112 $this->$method($config[$setting]);
200 $this->port = (int)
$port;
226 $username = $this->safeStorage->retrieveSafely(
'username');
228 return $username !== null ? $username :
'anonymous';
240 $this->safeStorage->storeSafely(
'username', $username);
252 return $this->safeStorage->retrieveSafely(
'password');
264 $this->safeStorage->storeSafely(
'password',
$password);
341 while ($item = array_shift($listing)) {
342 if (preg_match(
'#^.*:$#', $item)) {
343 $base = trim($item,
':');
362 $compare =
function ($one, $two) {
363 return strnatcmp($one[
'path'], $two[
'path']);
366 usort($result, $compare);
404 $item = preg_replace(
'#\s+#',
' ', trim($item), 7);
406 if (count(explode(
' ', $item, 9)) !== 9) {
407 throw new RuntimeException(
"Metadata can't be parsed from item '$item' , not enough parts.");
410 list($permissions, , , ,
$size, , , ,
$name) = explode(
' ', $item, 9);
414 if (
$type ===
'dir') {
415 return compact(
'type',
'path');
422 return compact(
'type',
'path',
'visibility',
'size');
435 $item = preg_replace(
'#\s+#',
' ', trim($item), 3);
437 if (count(explode(
' ', $item, 4)) !== 4) {
438 throw new RuntimeException(
"Metadata can't be parsed from item '$item' , not enough parts.");
445 $format = strlen($date) === 8 ?
'm-d-yH:iA' :
'Y-m-dH:i';
446 $dt = DateTime::createFromFormat(
$format, $date .
$time);
447 $timestamp = $dt ? $dt->getTimestamp() : (int) strtotime(
"$date $time");
449 if (
$size ===
'<DIR>') {
452 return compact(
'type',
'path',
'timestamp');
459 return compact(
'type',
'path',
'visibility',
'size',
'timestamp');
471 return preg_match(
'/^[0-9]{2,4}-[0-9]{2}-[0-9]{2}/', $item) ?
'windows' :
'unix';
483 return substr($permissions, 0, 1) ===
'd' ?
'dir' :
'file';
496 $permissions = substr($permissions, 1);
499 $map = [
'-' =>
'0',
'r' =>
'4',
'w' =>
'2',
'x' =>
'1'];
500 $permissions = strtr($permissions, $map);
503 $parts = str_split($permissions, 3);
506 $mapper =
function ($part) {
507 return array_sum(str_split($part));
511 return array_sum(array_map($mapper, $parts));
523 $filter =
function ($line) {
524 if ( ! empty($line) && ! preg_match(
'#.* \.(\.)?$|^total#', $line)) {
531 return array_filter($list, $filter);
565 if ( ! empty($dirname) && ! $this->
has($dirname)) {
617 abstract public function connect();
setRoot($root)
Set the root folder to work from.
const VISIBILITY_PUBLIC
VISIBILITY_PUBLIC public visibility
if(isset($_REQUEST['delete'])) $list
getSize($path)
Get the size of a file.array|false
ensureDirectory($dirname)
Ensure a directory exists.
setPassword($password)
Set the ftp password.
createDir($dirname, Config $config)
Create a directory.
listContents($directory='', $recursive=false)
List contents of a directory.array
setHost($host)
Set the host.
setTimeout($timeout)
Set the amount of seconds before the connection should timeout.
normalizeWindowsObject($item, $base)
Normalize a Windows/DOS file entry.
connect()
Establish a connection.
getUsername()
Returns the ftp username.
getHost()
Returns the host.
normalizeObject($item, $base)
Normalize a file entry.
__construct(array $config)
Constructor.
setPort($port)
Set the ftp port.
detectType($permissions)
Get the file type from the permissions.
const VISIBILITY_PRIVATE
VISIBILITY_PRIVATE private visibility
static forFtpSystemType($systemType)
Create a new exception for a link.
setConfig(array $config)
Set the config.
isConnected()
Check if a connection is active.
getMetadata($path)
Get all the meta data of a file or directory.
listDirectoryContents($directory, $recursive=false)
normalizeUnixObject($item, $base)
Normalize a Unix file entry.
getRoot()
Returns the root folder to work from.
getTimeout()
Returns the amount of seconds before the connection will timeout.
sortListing(array $result)
Sort a directory listing.
detectSystemType($item)
Get the system type from a listing item.
disconnect()
Close the connection.
has($path)
Check whether a file exists.array|bool|null
Create styles array
The data for the language used.
normalizeListing(array $listing, $prefix='')
Normalize a directory listing.
getSystemType()
Return the FTP system type.
removeDotDirectories(array $list)
Filter out dot-directories.
foreach($mandatory_scripts as $file) $timestamp
setSystemType($systemType)
Set the FTP system type (windows or unix).
setUsername($username)
Set ftp username.
normalizePermissions($permissions)
Normalize a permissions string.
setPermPrivate($permPrivate)
Set the private permission value.
getVisibility($path)
Get the visibility of a file.array|false
getPassword()
Returns the password.
__destruct()
Disconnect on destruction.
setPermPublic($permPublic)
Set the public permission value.
getPermPrivate()
Get the private permission value.
getPermPublic()
Get the public permission value.
getPort()
Returns the ftp port.