PHP Class FtpClient\FtpClient

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

Protected Properties

Property Type Description
$conn resource The connection with the server.

Public Methods

Method 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.

Protected Methods

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

Method Details

__call() public method

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
return mixed

__construct() public method

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

__destruct() public method

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

cleanDir() public method

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

close() public method

Closes the current FTP connection.
public close ( ) : boolean
return boolean

connect() public method

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
return FTPClient

count() public method

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
return integer

dirSize() public method

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
return integer The size in bytes.

getConnection() public method

Get the connection with the server.
public getConnection ( ) : resource
return resource

getWrapper() public method

Get the wrapper.
public getWrapper ( ) : FtpWrapper
return FtpWrapper

help() public method

Get the help information of the remote FTP server.
public help ( ) : array
return array

isDir() public method

Check if a directory exist.
public isDir ( string $directory ) : boolean
$directory string
return boolean

isEmpty() public method

Check if a directory is empty.
public isEmpty ( string $directory ) : boolean
$directory string
return boolean

login() public method

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

mkdir() public method

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
return array

modifiedTime() public method

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

nlist() public method

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).
return array

parseRawList() public method

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

putAll() public method

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

putFromPath() public method

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

putFromString() public method

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

rawToType() public method

..) 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
return string The file type (file, directory, link, unknown)

rawlist() public method

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
return array

remove() public method

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()}
return boolean

rmdir() public method

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
return boolean

scanDir() public method

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
return array

setPhpLimit() public method

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
return FtpClient

setWrapper() protected method

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

up() public method

Changes to the parent directory.
public up ( ) : FtpClient
return FtpClient

Property Details

$conn protected_oe property

The connection with the server.
protected resource $conn
return resource