FTPManager

Extends \org\turbocommons\src\main\php\model\BaseStrictClass

A Synchronous class to manage and operate with ftp connections

package

Default

Methods

Class constructor initializes the FTP connection with the specified parameters

__construct(string $userName, string $psw, string $host, integer $port = null, integer $timeout = 90) 

Arguments

$userName

string

The username for the ftp session we want to start

$psw

string

The password for the ftp user

$host

string

The FTP server address. This parameter shouldn't have any trailing slashes and shouldn't be prefixed with ftp://.

$port

integer

This parameter specifies an alternate port to connect to. If it is omitted or set to zero, then the default FTP port, 21, will be used.

$timeout

integer

This parameter specifies the timeout for all subsequent network operations. If omitted, the default value is 90 seconds. The timeout can be changed and queried at any time

Ftp destructor will always close the current connection to avoid problems with opened connections.

__destruct() 

Protection to prevent accessing undefined properties to this class

__get(string $name) : void
inherited

Arguments

$name

string

The property name

Protection to prevent creating extra properties to this class

__set(string $name, string $value) : void
inherited

Arguments

$name

string

The property name

$value

string

The property value

Terminate the current FTP connection

closeConnection() : void

Create a file to the specified ftp path and write the specified data to it.

createFile(string $ftpPath, string $fileData = '') : boolean

Arguments

$ftpPath

string

The full ftp path where the file will be stored, including the full file name

$fileData

string

Information to store on the file (a string, a block of bytes, etc...)

Response

boolean

Returns true on success or false on failure.

Get a file from an ftp path and store it directly to the specified file path (If the specified file exists, will be overriden).

downloadFile(string $ftpPath, string $localPath) : boolean

Arguments

$ftpPath

string

The file full ftp path including the file name

$localPath

string

The local path where the file will be stored, including the filename where the data will be saved.

Response

boolean

True on sucess or false if the download fails

Gives the list of items that are stored on the specified ftp folder. It will give files and directories, and each element will be the item name, without the path to it.

getDirectoryList(string $path = '/') : array

The contents of any subfolder will not be listed. We must call this method for each child folder if we want to get it's list.

Arguments

$path

string

Full path to the directory we want to list. Example: 'folder/' by default the root ftp folder is used ('/')

Response

array

The list of item names inside the specified path

Read and return an ftp file contents. Remember that big files may become problematic as we are only using memory to read the file data, the file is not stored no disk.

readFile(string $ftpPath) : string

Arguments

$ftpPath

string

The file full ftp path including the file name

Response

string

The file binary information

Properties

Variable that contains the last error that happened (if any).

lastError : 

Type(s)

Define the type of data transfer for the ftp connection: FTP_BINARY (default and recommended) or FTP_ASCII

transferMode : 

Type(s)