Oihana Php Ftp

FtpFileTrait

Provides the single-file operations of the {@see \oihana\ftp\FtpClient}: download, upload, append, delete, rename, size, last-modified time and permission changes.

Every method requires an open connection (see FtpConnectionTrait::connect()) and funnels through the FtpDriverInterface, raising an FtpTransferException when the underlying operation fails.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Methods

append()  : static
Appends the contents of a local file to a remote file.
chmod()  : static
Changes the permissions of a remote file.
delete()  : static
Deletes a remote file.
download()  : static
Downloads a remote file to the local filesystem.
exists()  : bool
Indicates whether a remote file exists (and exposes a readable size).
lastModified()  : int
Returns the last-modified time of a remote file, as a Unix timestamp.
rename()  : static
Renames or moves a remote file or directory.
size()  : int
Returns the size of a remote file, in bytes.
upload()  : static
Uploads a local file to the server.
assertLocalFile()  : void
Asserts that a local file exists and is readable.
resolveTransferMode()  : int
Resolves a transfer-mode string to its `ext-ftp` resource value.

Methods

append()

Appends the contents of a local file to a remote file.

public append(string $localFile, string $remoteFile[, string|null $mode = null ]) : static
Parameters
$localFile : string

The source path on the local filesystem.

$remoteFile : string

The destination path on the server.

$mode : string|null = null

The transfer mode; defaults to the client's configured mode.

Tags
throws
FtpTransferException

When the local file is missing, the append fails, or no connection is open.

Return values
static

This instance, for chaining.

chmod()

Changes the permissions of a remote file.

public chmod(string $remoteFile, int $permissions) : static
Parameters
$remoteFile : string

The remote path.

$permissions : int

The new permissions, as an octal value (e.g. 0644).

Tags
throws
FtpTransferException

When the change fails or no connection is open.

Return values
static

This instance, for chaining.

delete()

Deletes a remote file.

public delete(string $remoteFile) : static
Parameters
$remoteFile : string

The path of the file to delete.

Tags
throws
FtpTransferException

When the deletion fails or no connection is open.

Return values
static

This instance, for chaining.

download()

Downloads a remote file to the local filesystem.

public download(string $remoteFile, string $localFile[, string|null $mode = null ][, bool $createDirectory = true ]) : static
Parameters
$remoteFile : string

The source path on the server.

$localFile : string

The destination path on the local filesystem.

$mode : string|null = null

The transfer mode (one of FtpTransferMode); defaults to the client's configured mode.

$createDirectory : bool = true

Whether to create the local parent directory if missing.

Tags
throws
DirectoryException
FtpTransferException

When the download fails or no connection is open.

Return values
static

This instance, for chaining.

exists()

Indicates whether a remote file exists (and exposes a readable size).

public exists(string $remoteFile) : bool

Directories and files whose size the server refuses to report are treated as absent.

Parameters
$remoteFile : string

The remote path.

Tags
throws
FtpTransferException

When no connection is open.

Return values
bool

True when the file exists with a known size.

lastModified()

Returns the last-modified time of a remote file, as a Unix timestamp.

public lastModified(string $remoteFile) : int

Not every server supports the underlying MDTM command.

Parameters
$remoteFile : string

The remote path.

Tags
throws
FtpTransferException

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

Return values
int

The Unix timestamp.

rename()

Renames or moves a remote file or directory.

public rename(string $from, string $to) : static
Parameters
$from : string

The current path.

$to : string

The new path.

Tags
throws
FtpTransferException

When the rename fails or no connection is open.

Return values
static

This instance, for chaining.

size()

Returns the size of a remote file, in bytes.

public size(string $remoteFile) : int
Parameters
$remoteFile : string

The remote path.

Tags
throws
FtpTransferException

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

Return values
int

The size in bytes.

upload()

Uploads a local file to the server.

public upload(string $localFile, string $remoteFile[, string|null $mode = null ]) : static
Parameters
$localFile : string

The source path on the local filesystem.

$remoteFile : string

The destination path on the server.

$mode : string|null = null

The transfer mode; defaults to the client's configured mode.

Tags
throws
FtpTransferException

When the local file is missing, the upload fails, or no connection is open.

Return values
static

This instance, for chaining.

assertLocalFile()

Asserts that a local file exists and is readable.

private assertLocalFile(string $localFile) : void
Parameters
$localFile : string

The local path.

Tags
throws
FtpTransferException

When the file is missing or unreadable.

resolveTransferMode()

Resolves a transfer-mode string to its `ext-ftp` resource value.

private resolveTransferMode(string|null $mode) : int
Parameters
$mode : string|null

The requested mode, or null to use the configured default.

Return values
int

Either FTP_ASCII or FTP_BINARY.

On this page

Search results