53 'ignorePassiveAddress',
72 $this->transferMode = $mode;
86 $this->ssl = (bool)
$ssl;
122 $this->utf8 = (bool)
$utf8;
136 if ( ! $this->connection) {
153 $response = ftp_raw($this->connection,
"OPTS UTF8 ON");
154 if (substr(
$response[0], 0, 3) !==
'200') {
156 'Could not set UTF-8 mode for connection: ' . $this->
getHost() .
'::' . $this->
getPort()
169 if (is_bool($this->ignorePassiveAddress) &&
defined(
'FTP_USEPASVADDRESS')) {
170 ftp_set_option($this->connection, FTP_USEPASVADDRESS, ! $this->ignorePassiveAddress);
173 if ( ! ftp_pasv($this->connection, $this->passive)) {
175 'Could not set passive mode for connection: ' . $this->
getHost() .
'::' . $this->
getPort()
206 set_error_handler(
function () {});
207 $isLoggedIn = ftp_login(
212 restore_error_handler();
214 if ( ! $isLoggedIn) {
217 'Could not login with connection: ' . $this->
getHost() .
'::' . $this->
getPort(
228 if (is_resource($this->connection)) {
229 ftp_close($this->connection);
232 $this->connection = null;
240 $stream = fopen(
'php://temp',
'w+b');
267 if ($visibility = $config->
get(
'visibility')) {
273 return compact(
'type',
'path',
'visibility');
317 if ($object[
'type'] ===
'file') {
321 } elseif ( ! ftp_rmdir(
$connection, $object[
'path'])) {
335 $directories = explode(
'/', $dirname);
337 foreach ($directories as $directory) {
349 return [
'type' =>
'dir',
'path' => $dirname];
365 foreach ($listing as
$key => $item) {
366 if (preg_match(
'~^\./.*~', $item)) {
367 $listing[
$key] = substr($item, 2);
371 if (in_array($directory, $listing,
true)) {
375 return (
boolean) ftp_mkdir(
$connection, $directory);
386 return [
'type' =>
'dir',
'path' =>
''];
392 return [
'type' =>
'dir',
'path' =>
$path];
397 if (empty($listing) || in_array(
'total 0', $listing,
true)) {
401 if (preg_match(
'/.* not found/', $listing[0])) {
405 if (preg_match(
'/^total [0-9]*$/', $listing[0])) {
406 array_shift($listing);
445 $object[
'contents'] = stream_get_contents($object[
'stream']);
446 fclose($object[
'stream']);
447 unset($object[
'stream']);
457 $stream = fopen(
'php://temp',
'w+b');
467 return [
'type' =>
'file',
'path' =>
$path,
'stream' =>
$stream];
481 return compact(
'path',
'visibility');
491 $directory = str_replace(
'*',
'\\*', $directory);
493 if ($recursive && $this->recurseManually) {
497 $options = $recursive ?
'-alnR' :
'-aln';
513 foreach ($listing as $directory) {
515 if ($directory[
'type'] !==
'dir')
continue;
532 return is_resource($this->connection) && ftp_rawlist($this->connection,
'/') !==
false;
534 if (strpos($e->getMessage(),
'ftp_rawlist') ===
false) {
547 $response = ftp_raw($this->connection,
'HELP');
549 return stripos(implode(
' ',
$response),
'Pure-FTPd') !==
false;
564 if ($this->isPureFtpd) {
connect()
Connect to the FTP server.
const VISIBILITY_PUBLIC
VISIBILITY_PUBLIC public visibility
static detectByFilename($filename)
ensureDirectory($dirname)
Ensure a directory exists.
isConnected()
Check if the connection is open.
setTransferMode($mode)
Set the transfer mode.
static dirname($path)
Get a normalized dirname from a path.
updateStream($path, $resource, Config $config)
Update a file using a stream.Config objectarray|false false on failure file meta data on success ...
read($path)
Read a file.array|false
setSsl($ssl)
Set if Ssl is enabled.
static guessMimeType($path, $content)
Guess MIME Type based on the path of the file and it's content.
listDirectoryContentsRecursive($directory)
setRecurseManually($recurseManually)
setUtf8Mode()
Set the connection to UTF-8 mode.
getUsername()
Returns the ftp username.
update($path, $contents, Config $config)
Update a file.Config objectarray|false false on failure file meta data on success ...
getTimestamp($path)
Get the timestamp of a file.array|false
getHost()
Returns the host.
normalizeObject($item, $base)
Normalize a file entry.
$metadata['__DYNAMIC:1__']
deleteDir($dirname)
Delete a directory.bool
$stream
PHP stream implementation.
setPassive($passive=true)
Set if passive mode should be used.
getMimetype($path)
Get the mimetype of a file.array|false
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
createDir($dirname, Config $config)
Create a directory.directory name array|false
getRoot()
Returns the root folder to work from.
setVisibility($path, $visibility)
Set the visibility for a file.array|false file meta data
setIgnorePassiveAddress($ignorePassiveAddress)
ftpRawlist($options, $path)
The ftp_rawlist function with optional escaping.
getTimeout()
Returns the amount of seconds before the connection will timeout.
createActualDirectory($directory, $connection)
Create a directory.
normalizeListing(array $listing, $prefix='')
Normalize a directory listing.
getMetadata($path)
Get all the meta data of a file or directory.array|false
foreach($mandatory_scripts as $file) $timestamp
rename($path, $newpath)
Rename a file.bool
writeStream($path, $resource, Config $config)
Write a new file using a stream.Config objectarray|false false on failure file meta data on success ...
listDirectoryContents($directory, $recursive=true)
write($path, $contents, Config $config)
Write a new file.Config objectarray|false false on failure file meta data on success ...
getPassword()
Returns the password.
readStream($path)
Read a file as a stream.array|false
setConnectionPassiveMode()
Set the connections to passive mode.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
getPermPrivate()
Get the private permission value.
getPermPublic()
Get the public permission value.
getPort()
Returns the ftp port.
setConnectionRoot()
Set the connection root.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
get($key, $default=null)
Get a setting.
disconnect()
Disconnect from the FTP server.