Oihana Php Ftp

FtpDirectoryTrait

Provides the directory operations of the {@see \oihana\ftp\FtpClient}: create, remove, navigate, and list remote directories.

Listings are returned either as raw names (listNames()), raw server lines (rawList()) or as structured FtpFile entries (listFiles(), which prefers MLSD and falls back to parsing ls -l output).

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Methods

changeDirectory()  : static
Changes the current working directory.
createDirectories()  : static
Creates a directory and every missing parent along the path (best effort).
createDirectory()  : static
Creates a remote directory.
currentDirectory()  : string
Returns the current working directory.
listFiles()  : array<int, FtpFile>
Returns the structured entries of a directory.
listNames()  : array<int, string>
Returns the names of the entries in a directory.
parentDirectory()  : static
Moves up to the parent directory.
rawList()  : array<int, string>
Returns the raw, server-formatted listing of a directory.
removeDirectory()  : static
Removes a remote directory.

Methods

changeDirectory()

Changes the current working directory.

public changeDirectory(string $directory) : static
Parameters
$directory : string

The target directory.

Tags
throws
FtpTransferException

When the change fails or no connection is open.

Return values
static

This instance, for chaining.

createDirectories()

Creates a directory and every missing parent along the path (best effort).

public createDirectories(string $path) : static

Each path segment is created in turn; segments that already exist are silently skipped, mirroring mkdir -p.

Parameters
$path : string

The directory path to create.

Tags
throws
FtpTransferException

When no connection is open.

Return values
static

This instance, for chaining.

createDirectory()

Creates a remote directory.

public createDirectory(string $directory) : static
Parameters
$directory : string

The directory to create.

Tags
throws
FtpTransferException

When the creation fails or no connection is open.

Return values
static

This instance, for chaining.

currentDirectory()

Returns the current working directory.

public currentDirectory() : string
Tags
throws
FtpTransferException

When the directory cannot be determined or no connection is open.

Return values
string

The absolute path of the current directory.

listFiles()

Returns the structured entries of a directory.

public listFiles([string $directory = '.' ]) : array<int, FtpFile>

Prefers the MLSD listing when the server supports it; otherwise falls back to parsing the raw ls -l output.

Parameters
$directory : string = '.'

The directory to list (defaults to the current directory).

Tags
throws
FtpTransferException

When the listing fails or no connection is open.

Return values
array<int, FtpFile>

The structured entries.

listNames()

Returns the names of the entries in a directory.

public listNames([string $directory = '.' ]) : array<int, string>
Parameters
$directory : string = '.'

The directory to list (defaults to the current directory).

Tags
throws
FtpTransferException

When the listing fails or no connection is open.

Return values
array<int, string>

The entry names.

parentDirectory()

Moves up to the parent directory.

public parentDirectory() : static
Tags
throws
FtpTransferException

When the change fails or no connection is open.

Return values
static

This instance, for chaining.

rawList()

Returns the raw, server-formatted listing of a directory.

public rawList([string $directory = '.' ][, bool $recursive = false ]) : array<int, string>
Parameters
$directory : string = '.'

The directory to list (defaults to the current directory).

$recursive : bool = false

Whether to recurse into sub-directories.

Tags
throws
FtpTransferException

When the listing fails or no connection is open.

Return values
array<int, string>

The raw listing lines.

removeDirectory()

Removes a remote directory.

public removeDirectory(string $directory) : static
Parameters
$directory : string

The directory to remove.

Tags
throws
FtpTransferException

When the removal fails or no connection is open.

Return values
static

This instance, for chaining.

On this page

Search results