53        'ignorePassiveAddress',
 
   72        $this->transferMode = $mode;
 
   86        $this->ssl = (bool) 
$ssl;
 
  122        $this->utf8 = (bool) 
$utf8;
 
  136        if ( ! $this->connection) {
 
  137            throw new RuntimeException(
'Could not connect to host: ' . $this->
getHost() . 
', port:' . $this->
getPort());
 
  153            $response = ftp_raw($this->connection, 
"OPTS UTF8 ON");
 
  154            if (substr(
$response[0], 0, 3) !== 
'200') {
 
  155                throw new RuntimeException(
 
  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)) {
 
  174            throw new RuntimeException(
 
  175                'Could not set passive mode for connection: ' . $this->
getHost() . 
'::' . $this->
getPort()
 
  189            throw new RuntimeException(
'Root is invalid or does not exist: ' . $this->
getRoot());
 
  206        set_error_handler(
function () {});
 
  207        $isLoggedIn = ftp_login(
 
  212        restore_error_handler();
 
  214        if ( ! $isLoggedIn) {
 
  216            throw new RuntimeException(
 
  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');
 
  250        $result[
'contents'] = $contents;
 
  267        if ($visibility = 
$config->get(
'visibility')) {
 
  273        return compact(
'type', 
'path', 
'visibility');
 
  316        foreach ($contents as $object) {
 
  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;
 
  533        } 
catch (ErrorException $e) {
 
  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) {
 
$metadata['__DYNAMIC:1__']
foreach($mandatory_scripts as $file) $timestamp
An exception for terminatinating execution or to throw for unit testing.
normalizeListing(array $listing, $prefix='')
Normalize a directory listing.
getRoot()
Returns the root folder to work from.
getPassword()
Returns the password.
ensureDirectory($dirname)
Ensure a directory exists.
getTimeout()
Returns the amount of seconds before the connection will timeout.
getHost()
Returns the host.
getPermPublic()
Get the public permission value.
getPort()
Returns the ftp port.
getPermPrivate()
Get the private permission value.
getUsername()
Returns the ftp username.
normalizeObject($item, $base)
Normalize a file entry.
setIgnorePassiveAddress($ignorePassiveAddress)
deleteDir($dirname)
Delete a directory.bool
setUtf8Mode()
Set the connection to UTF-8 mode.
listDirectoryContents($directory, $recursive=true)
getMimetype($path)
Get the mimetype of a file.array|false
read($path)
Read a file.array|false
write($path, $contents, Config $config)
Write a new file.array|false false on failure file meta data on success
setPassive($passive=true)
Set if passive mode should be used.
getTimestamp($path)
Get the timestamp of a file.array|false
createDir($dirname, Config $config)
Create a directory.array|false
update($path, $contents, Config $config)
Update a file.array|false false on failure file meta data on success
setVisibility($path, $visibility)
Set the visibility for a file.array|false file meta data
listDirectoryContentsRecursive($directory)
setConnectionRoot()
Set the connection root.
setTransferMode($mode)
Set the transfer mode.
disconnect()
Disconnect from the FTP server.
setSsl($ssl)
Set if Ssl is enabled.
setRecurseManually($recurseManually)
createActualDirectory($directory, $connection)
Create a directory.
updateStream($path, $resource, Config $config)
Update a file using a stream.array|false false on failure file meta data on success
rename($path, $newpath)
Rename a file.bool
ftpRawlist($options, $path)
The ftp_rawlist function with optional escaping.
connect()
Connect to the FTP server.
readStream($path)
Read a file as a stream.array|false
isConnected()
Check if the connection is open.
writeStream($path, $resource, Config $config)
Write a new file using a stream.array|false false on failure file meta data on success
setConnectionPassiveMode()
Set the connections to passive mode.
getMetadata($path)
Get all the meta data of a file or directory.array|false
static detectByFilename($filename)
static dirname($path)
Get a normalized dirname from a path.
static guessMimeType($path, $content)
Guess MIME Type based on the path of the file and it's content.
const VISIBILITY_PUBLIC
@const VISIBILITY_PUBLIC public visibility
$stream
PHP stream implementation.