PHP Class CI_FTP, TastyIgniter

Author: EllisLab Dev Team
Show file Open project: tastyigniter/tastyigniter Class Usage Examples

Public Properties

Property Type Description
$debug boolean Specifies whether to display error messages.
$hostname string FTP Server hostname
$passive boolean Passive mode flag
$password string FTP Password
$port integer FTP Server port
$username string FTP Username

Protected Properties

Property Type Description
$conn_id resource Connection ID

Public Methods

Method Description
__construct ( array $config = [] ) : void Constructor
changedir ( string $path, boolean $suppress_debug = FALSE ) : boolean Change directory
chmod ( string $path, integer $perm ) : boolean Set file permissions
close ( ) : boolean Close the connection
connect ( array $config = [] ) : boolean FTP Connect
delete_dir ( string $filepath ) : boolean Delete a folder and recursively delete everything (including sub-folders) contained within it.
delete_file ( string $filepath ) : boolean Rename (or move) a file
download ( string $rempath, string $locpath, string $mode = 'auto' ) : boolean Download a file from a remote server to the local server
initialize ( array $config = [] ) : void Initialize preferences
list_files ( string $path = '.' ) : array FTP List files in the specified directory
mirror ( string $locpath, string $rempath ) : boolean Read a directory and recreate it remotely
mkdir ( string $path, integer $permissions = NULL ) : boolean Create a directory
move ( string $old_file, string $new_file ) : boolean Move a file
rename ( string $old_file, string $new_file, boolean $move = FALSE ) : boolean Rename (or move) a file
upload ( string $locpath, string $rempath, string $mode = 'auto', integer $permissions = NULL ) : boolean Upload a file to the server

Protected Methods

Method Description
_error ( string $line ) : void Display error message
_getext ( string $filename ) : string Extract the file extension
_is_conn ( ) : boolean Validates the connection ID
_login ( ) : boolean FTP Login
_settype ( string $ext ) : string Set the upload type

Method Details

__construct() public method

Constructor
public __construct ( array $config = [] ) : void
$config array
return void

_error() protected method

Display error message
protected _error ( string $line ) : void
$line string
return void

_getext() protected method

Extract the file extension
protected _getext ( string $filename ) : string
$filename string
return string

_is_conn() protected method

Validates the connection ID
protected _is_conn ( ) : boolean
return boolean

_login() protected method

FTP Login
protected _login ( ) : boolean
return boolean

_settype() protected method

Set the upload type
protected _settype ( string $ext ) : string
$ext string Filename extension
return string

changedir() public method

The second parameter lets us momentarily turn off debugging so that this function can be used to test for the existence of a folder without throwing an error. There's no FTP equivalent to is_dir() so we do it by trying to change to a particular directory. Internally, this parameter is only used by the "mirror" function below.
public changedir ( string $path, boolean $suppress_debug = FALSE ) : boolean
$path string
$suppress_debug boolean
return boolean

chmod() public method

Set file permissions
public chmod ( string $path, integer $perm ) : boolean
$path string File path
$perm integer Permissions
return boolean

close() public method

Close the connection
public close ( ) : boolean
return boolean

connect() public method

FTP Connect
public connect ( array $config = [] ) : boolean
$config array Connection values
return boolean

delete_dir() public method

Delete a folder and recursively delete everything (including sub-folders) contained within it.
public delete_dir ( string $filepath ) : boolean
$filepath string
return boolean

delete_file() public method

Rename (or move) a file
public delete_file ( string $filepath ) : boolean
$filepath string
return boolean

download() public method

Download a file from a remote server to the local server
public download ( string $rempath, string $locpath, string $mode = 'auto' ) : boolean
$rempath string
$locpath string
$mode string
return boolean

initialize() public method

Initialize preferences
public initialize ( array $config = [] ) : void
$config array
return void

list_files() public method

FTP List files in the specified directory
public list_files ( string $path = '.' ) : array
$path string
return array

mirror() public method

This function recursively reads a folder and everything it contains (including sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure of the original file path will be recreated on the server.
public mirror ( string $locpath, string $rempath ) : boolean
$locpath string Path to source with trailing slash
$rempath string Path to destination - include the base folder with trailing slash
return boolean

mkdir() public method

Create a directory
public mkdir ( string $path, integer $permissions = NULL ) : boolean
$path string
$permissions integer
return boolean

move() public method

Move a file
public move ( string $old_file, string $new_file ) : boolean
$old_file string
$new_file string
return boolean

rename() public method

Rename (or move) a file
public rename ( string $old_file, string $new_file, boolean $move = FALSE ) : boolean
$old_file string
$new_file string
$move boolean
return boolean

upload() public method

Upload a file to the server
public upload ( string $locpath, string $rempath, string $mode = 'auto', integer $permissions = NULL ) : boolean
$locpath string
$rempath string
$mode string
$permissions integer
return boolean

Property Details

$conn_id protected property

Connection ID
protected resource $conn_id
return resource

$debug public property

Specifies whether to display error messages.
public bool $debug
return boolean

$hostname public property

FTP Server hostname
public string $hostname
return string

$passive public property

Passive mode flag
public bool $passive
return boolean

$password public property

FTP Password
public string $password
return string

$port public property

FTP Server port
public int $port
return integer

$username public property

FTP Username
public string $username
return string