class FtpClient

FTP client class

Methods

__construct( array $options = array())

FtpClient object constructor

__destruct()

FtpClient object destructor

static  FtpClient
getInstance( string $host = '127.0.0.1', string $port = '21', array $options = array(), string $user = null, string $pass = null)

Returns the global FTP connector object, only creating it if it doesn't already exist.

boolean
setOptions( array $options)

Set client options

boolean
connect( string $host = '127.0.0.1', string $port = 21)

Method to connect to a FTP server

boolean
isConnected()

Method to determine if the object is connected to an FTP server

boolean
login( string $user = 'anonymous', string $pass = 'jftp@joomla.org')

Method to login to a server once connected

boolean
quit()

Method to quit and close the connection

string
pwd()

Method to retrieve the current working directory on the FTP server

string
syst()

Method to system string from the FTP server

boolean
chdir( string $path)

Method to change the current working directory on the FTP server

boolean
reinit()

Method to reinitialise the server, ie. need to login again

boolean
rename( string $from, string $to)

Method to rename a file/folder on the FTP server

boolean
chmod( string $path, mixed $mode)

Method to change mode for a path on the FTP server

boolean
delete( string $path)

Method to delete a path [file/folder] on the FTP server

boolean
mkdir( string $path)

Method to create a directory on the FTP server

boolean
restart( integer $point)

Method to restart data transfer at a given byte

boolean
create( string $path)

Method to create an empty file on the FTP server

boolean
read( string $remote, string $buffer)

Method to read a file from the FTP server's contents into a buffer

boolean
get( string $local, string $remote)

Method to get a file from the FTP server and save it to a local file

boolean
store( string $local, string $remote = null)

Method to store a file to the FTP server

boolean
write( string $remote, string $buffer)

Method to write a string to the FTP server

boolean
append( string $remote, string $buffer)

Method to append a string to the FTP server

mixed
size( string $remote)

Get the size of the remote file.

string
listNames( string $path = null)

Method to list the filenames of the contents of a directory on the FTP server

mixed
listDetails( string $path = null, string $type = 'all')

Method to list the contents of a directory on the FTP server

Details

__construct( array $options = array())

FtpClient object constructor

Parameters

array $options Associative array of options to set

__destruct()

FtpClient object destructor

Closes an existing connection, if we have one

static FtpClient getInstance( string $host = '127.0.0.1', string $port = '21', array $options = array(), string $user = null, string $pass = null)

Returns the global FTP connector object, only creating it if it doesn't already exist.

You may optionally specify a username and password in the parameters. If you do so, you may not login() again with different credentials using the same object. If you do not use this option, you must quit() the current connection when you are done, to free it for use by others.

Parameters

string $host Host to connect to
string $port Port to connect to
array $options Array with any of these options: type=>[FTPAUTOASCII|FTPASCII|FTP_BINARY], timeout=>(int)
string $user Username to use for a connection
string $pass Password to use for a connection

Return Value

FtpClient The FTP Client object.

boolean setOptions( array $options)

Set client options

Parameters

array $options Associative array of options to set

Return Value

boolean True if successful

boolean connect( string $host = '127.0.0.1', string $port = 21)

Method to connect to a FTP server

Parameters

string $host Host to connect to [Default: 127.0.0.1]
string $port Port to connect on [Default: port 21]

Return Value

boolean True if successful

boolean isConnected()

Method to determine if the object is connected to an FTP server

Return Value

boolean True if connected

boolean login( string $user = 'anonymous', string $pass = 'jftp@joomla.org')

Method to login to a server once connected

Parameters

string $user Username to login to the server
string $pass Password to login to the server

Return Value

boolean True if successful

boolean quit()

Method to quit and close the connection

Return Value

boolean True if successful

string pwd()

Method to retrieve the current working directory on the FTP server

Return Value

string Current working directory

string syst()

Method to system string from the FTP server

Return Value

string System identifier string

boolean chdir( string $path)

Method to change the current working directory on the FTP server

Parameters

string $path Path to change into on the server

Return Value

boolean True if successful

boolean reinit()

Method to reinitialise the server, ie. need to login again

NOTE: This command not available on all servers

Return Value

boolean True if successful

boolean rename( string $from, string $to)

Method to rename a file/folder on the FTP server

Parameters

string $from Path to change file/folder from
string $to Path to change file/folder to

Return Value

boolean True if successful

boolean chmod( string $path, mixed $mode)

Method to change mode for a path on the FTP server

Parameters

string $path Path to change mode on
mixed $mode Octal value to change mode to, e.g. '0777', 0777 or 511 (string or integer)

Return Value

boolean True if successful

boolean delete( string $path)

Method to delete a path [file/folder] on the FTP server

Parameters

string $path Path to delete

Return Value

boolean True if successful

boolean mkdir( string $path)

Method to create a directory on the FTP server

Parameters

string $path Directory to create

Return Value

boolean True if successful

boolean restart( integer $point)

Method to restart data transfer at a given byte

Parameters

integer $point Byte to restart transfer at

Return Value

boolean True if successful

boolean create( string $path)

Method to create an empty file on the FTP server

Parameters

string $path Path local file to store on the FTP server

Return Value

boolean True if successful

boolean read( string $remote, string $buffer)

Method to read a file from the FTP server's contents into a buffer

Parameters

string $remote Path to remote file to read on the FTP server
string $buffer &$buffer Buffer variable to read file contents into

Return Value

boolean True if successful

boolean get( string $local, string $remote)

Method to get a file from the FTP server and save it to a local file

Parameters

string $local Local path to save remote file to
string $remote Path to remote file to get on the FTP server

Return Value

boolean True if successful

boolean store( string $local, string $remote = null)

Method to store a file to the FTP server

Parameters

string $local Path to local file to store on the FTP server
string $remote FTP path to file to create

Return Value

boolean True if successful

boolean write( string $remote, string $buffer)

Method to write a string to the FTP server

Parameters

string $remote FTP path to file to write to
string $buffer Contents to write to the FTP server

Return Value

boolean True if successful

boolean append( string $remote, string $buffer)

Method to append a string to the FTP server

Parameters

string $remote FTP path to file to append to
string $buffer Contents to append to the FTP server

Return Value

boolean True if successful

mixed size( string $remote)

Get the size of the remote file.

Parameters

string $remote FTP path to file whose size to get

Return Value

mixed number of bytes or false on error

string listNames( string $path = null)

Method to list the filenames of the contents of a directory on the FTP server

Note: Some servers also return folder names. However, to be sure to list folders on all servers, you should use listDetails() instead if you also need to deal with folders

Parameters

string $path Path local file to store on the FTP server

Return Value

string Directory listing

mixed listDetails( string $path = null, string $type = 'all')

Method to list the contents of a directory on the FTP server

Parameters

string $path Path to the local file to be stored on the FTP server
string $type Return type [raw|all|folders|files]

Return Value

mixed If $type is raw: string Directory listing, otherwise array of string with file-names