PHP Class FtpClient\FtpClient

Author: Nicolas Tallefourtane ([email protected])
Inheritance: implements Countabl\Countable
Afficher le fichier Open project: nicolab/php-ftp-client Class Usage Examples

Protected Properties

Свойство Type Description
$conn resource The connection with the server.

Méthodes publiques

Méthode Description
__call ( string $method, array $arguments ) : mixed Call an internal method or a FTP method handled by the wrapper.
__construct ( resource | null $connection = null ) Constructor.
__destruct ( ) Close the connection when the object is destroyed.
cleanDir ( string $directory ) : boolean Empty directory.
close ( ) : boolean Closes the current FTP connection.
connect ( string $host, boolean $ssl = false, integer $port = 21, integer $timeout = 90 ) : FTPClient Open a FTP connection.
count ( string $directory = '.', string | null $type = null, boolean $recursive = true ) : integer Count the items (file, directory, link, unknown).
dirSize ( string $directory = '.', boolean $recursive = true ) : integer Returns the total size of the given directory in bytes.
getConnection ( ) : resource Get the connection with the server.
getWrapper ( ) : FtpWrapper Get the wrapper.
help ( ) : array Get the help information of the remote FTP server.
isDir ( string $directory ) : boolean Check if a directory exist.
isEmpty ( string $directory ) : boolean Check if a directory is empty.
login ( string $username = 'anonymous', string $password = '' ) : FtpClient Logs in to an FTP connection.
mkdir ( string $directory, boolean $recursive = false ) : array Creates a directory.
modifiedTime ( string $remoteFile, string | null $format = null ) : integer Returns the last modified time of the given file.
nlist ( string $directory = '.', boolean $recursive = false, callable $filter = 'sort' ) : array Returns a list of files in the given directory.
parseRawList ( array $rawlist ) : array Parse raw list.
putAll ( string $source_directory, string $target_directory, integer $mode = FTP_BINARY ) : FtpClient Upload files.
putFromPath ( string $local_file ) : FtpClient Uploads a file to the server.
putFromString ( string $remote_file, string $content ) : FtpClient Uploads a file to the server from a string.
rawToType ( string $permission ) : string Convert raw info (drwx---r-x .
rawlist ( string $directory = '.', boolean $recursive = false ) : array Returns a detailed list of files in the given directory.
remove ( string $path, boolean $recursive = false ) : boolean Remove a file or a directory.
rmdir ( string $directory, boolean $recursive = true ) : boolean Remove a directory.
scanDir ( string $directory = '.', boolean $recursive = false ) : array Scan a directory and returns the details of each item.
setPhpLimit ( string | null $memory = null, integer $time_limit, boolean $ignore_user_abort = true ) : FtpClient Overwrites the PHP limit
up ( ) : FtpClient Changes to the parent directory.

Méthodes protégées

Méthode Description
setWrapper ( FtpWrapper $wrapper ) : FtpClient Set the wrapper which forward the PHP FTP functions to use in FtpClient instance.

Method Details

__call() public méthode

Wrap the FTP PHP functions to call as method of FtpClient object. The connection is automaticaly passed to the FTP PHP functions.
public __call ( string $method, array $arguments ) : mixed
$method string
$arguments array
Résultat mixed

__construct() public méthode

Constructor.
public __construct ( resource | null $connection = null )
$connection resource | null

__destruct() public méthode

Close the connection when the object is destroyed.
public __destruct ( )

cleanDir() public méthode

Empty directory.
See also: FtpClient::remove()
See also: FtpClient::delete()
See also: FtpClient::rmdir()
public cleanDir ( string $directory ) : boolean
$directory string
Résultat boolean

close() public méthode

Closes the current FTP connection.
public close ( ) : boolean
Résultat boolean

connect() public méthode

Open a FTP connection.
public connect ( string $host, boolean $ssl = false, integer $port = 21, integer $timeout = 90 ) : FTPClient
$host string
$ssl boolean
$port integer
$timeout integer
Résultat FTPClient

count() public méthode

Count the items (file, directory, link, unknown).
public count ( string $directory = '.', string | null $type = null, boolean $recursive = true ) : integer
$directory string The directory, by default is the current directory.
$type string | null The type of item to count (file, directory, link, unknown)
$recursive boolean true by default
Résultat integer

dirSize() public méthode

Returns the total size of the given directory in bytes.
public dirSize ( string $directory = '.', boolean $recursive = true ) : integer
$directory string The directory, by default is the current directory.
$recursive boolean true by default
Résultat integer The size in bytes.

getConnection() public méthode

Get the connection with the server.
public getConnection ( ) : resource
Résultat resource

getWrapper() public méthode

Get the wrapper.
public getWrapper ( ) : FtpWrapper
Résultat FtpWrapper

help() public méthode

Get the help information of the remote FTP server.
public help ( ) : array
Résultat array

isDir() public méthode

Check if a directory exist.
public isDir ( string $directory ) : boolean
$directory string
Résultat boolean

isEmpty() public méthode

Check if a directory is empty.
public isEmpty ( string $directory ) : boolean
$directory string
Résultat boolean

login() public méthode

Logs in to an FTP connection.
public login ( string $username = 'anonymous', string $password = '' ) : FtpClient
$username string
$password string
Résultat FtpClient

mkdir() public méthode

Creates a directory.
See also: FtpClient::rmdir()
See also: FtpClient::remove()
See also: FtpClient::put()
See also: FtpClient::putAll()
public mkdir ( string $directory, boolean $recursive = false ) : array
$directory string The directory
$recursive boolean
Résultat array

modifiedTime() public méthode

Return -1 on error
public modifiedTime ( string $remoteFile, string | null $format = null ) : integer
$remoteFile string
$format string | null
Résultat integer

nlist() public méthode

Returns a list of files in the given directory.
public nlist ( string $directory = '.', boolean $recursive = false, callable $filter = 'sort' ) : array
$directory string The directory, by default is "." the current directory
$recursive boolean
$filter callable A callable to filter the result, by default is asort() PHP function. The result is passed in array argument, must take the argument by reference ! The callable should proceed with the reference array because is the behavior of several PHP sorting functions (by reference ensure directly the compatibility with all PHP sorting functions).
Résultat array

parseRawList() public méthode

Parse raw list.
See also: FtpClient::rawlist()
See also: FtpClient::scanDir()
See also: FtpClient::dirSize()
public parseRawList ( array $rawlist ) : array
$rawlist array
Résultat array

putAll() public méthode

Upload files.
public putAll ( string $source_directory, string $target_directory, integer $mode = FTP_BINARY ) : FtpClient
$source_directory string
$target_directory string
$mode integer
Résultat FtpClient

putFromPath() public méthode

Uploads a file to the server.
public putFromPath ( string $local_file ) : FtpClient
$local_file string
Résultat FtpClient

putFromString() public méthode

Uploads a file to the server from a string.
public putFromString ( string $remote_file, string $content ) : FtpClient
$remote_file string
$content string
Résultat FtpClient

rawToType() public méthode

..) to type (file, directory, link, unknown). Only the first char is used for resolving.
public rawToType ( string $permission ) : string
$permission string Example : drwx---r-x
Résultat string The file type (file, directory, link, unknown)

rawlist() public méthode

Returns a detailed list of files in the given directory.
See also: FtpClient::nlist()
See also: FtpClient::scanDir()
See also: FtpClient::dirSize()
public rawlist ( string $directory = '.', boolean $recursive = false ) : array
$directory string The directory, by default is the current directory
$recursive boolean
Résultat array

remove() public méthode

Remove a file or a directory.
See also: FtpClient::rmdir()
See also: FtpClient::cleanDir()
See also: FtpClient::delete()
public remove ( string $path, boolean $recursive = false ) : boolean
$path string The path of the file or directory to remove
$recursive boolean Is effective only if $path is a directory, {@see \FtpClient::rmdir()}
Résultat boolean

rmdir() public méthode

Remove a directory.
See also: FtpClient::mkdir()
See also: FtpClient::cleanDir()
See also: FtpClient::remove()
See also: FtpClient::delete()
public rmdir ( string $directory, boolean $recursive = true ) : boolean
$directory string
$recursive boolean Forces deletion if the directory is not empty
Résultat boolean

scanDir() public méthode

Scan a directory and returns the details of each item.
See also: FtpClient::nlist()
See also: FtpClient::rawlist()
See also: FtpClient::parseRawList()
See also: FtpClient::dirSize()
public scanDir ( string $directory = '.', boolean $recursive = false ) : array
$directory string
$recursive boolean
Résultat array

setPhpLimit() public méthode

Overwrites the PHP limit
public setPhpLimit ( string | null $memory = null, integer $time_limit, boolean $ignore_user_abort = true ) : FtpClient
$memory string | null The memory limit, if null is not modified
$time_limit integer The max execution time, unlimited by default
$ignore_user_abort boolean Ignore user abort, true by default
Résultat FtpClient

setWrapper() protected méthode

Set the wrapper which forward the PHP FTP functions to use in FtpClient instance.
protected setWrapper ( FtpWrapper $wrapper ) : FtpClient
$wrapper FtpWrapper
Résultat FtpClient

up() public méthode

Changes to the parent directory.
public up ( ) : FtpClient
Résultat FtpClient

Property Details

$conn protected_oe property

The connection with the server.
protected resource $conn
Résultat resource