apidoc
[ class tree: apidoc ] [ index: apidoc ] [ all elements ]

Class: Net_FTP

Source Location: /Net_FTP-1.3.0RC1/Net/FTP.php

Class Overview

PEAR
   |
   --Net_FTP

Class for comfortable FTP-communication


Author(s):

Methods


Inherited Variables

Inherited Methods


Class Details

[line 464]
Class for comfortable FTP-communication

This class provides comfortable communication with FTP-servers. You may do everything enabled by the PHP-FTP-extension and further functionalities, like recursive-deletion, -up- and -download. Another feature is to create directories recursively.



[ Top ]


Method Detail

Net_FTP (Constructor)   [line 607]

void Net_FTP( [string $host = null], [int $port = null], [int $timeout = 90])

This generates a new FTP-Object. The FTP-connection will not be established, yet.

You can leave $host and $port blank, if you want. The $host will not be set and the $port will be left at 21. You have to set the $host manualy before trying to connect or with the connect() method.

  • See: Net_FTP::setHostname(), Net_FTP::setPort(), Net_FTP::connect()
  • Access: public

Parameters:

string   $host   —  (optional) The hostname
int   $port   —  (optional) The port
int   $timeout   —  (optional) Sets the standard timeout

[ Top ]

addExtension   [line 1575]

void addExtension( int $mode, string $ext)

Adds an extension to a mode-directory The mode-directory saves file-extensions coresponding to filetypes (ascii e.g.: 'php', 'txt', 'htm',...; binary e.g.: 'jpg', 'gif', 'exe',...).

The extensions have to be saved without the '.'. And can be predefined in an external file (see: getExtensionsFile()).

The array is build like this: 'php' => FTP_ASCII, 'png' => FTP_BINARY

To change the mode of an extension, just add it again with the new mode!

  • Access: public

Parameters:

int   $mode   —  Either FTP_ASCII or FTP_BINARY
string   $ext   —  Extension

[ Top ]

attach   [line 1728]

boolean attach( &$observer, object $observer)

Adds a Net_FTP_Observer instance to the list of observers that are listening for messages emitted by this Net_FTP instance.
  • Return: True if the observer is successfully attached.
  • Since: 1.3
  • Access: public

Parameters:

object   $observer   —  The Net_FTP_Observer instance to attach as a listener.
   &$observer   — 

[ Top ]

cd   [line 711]

mixed cd( string $dir)

This changes the currently used directory. You can use either an absolute directory-path (e.g. "/home/blah") or a relative one (e.g. "../test").
  • Return: True on success, otherwise PEAR::Error
  • See: NET_FTP_ERR_DIRCHANGE_FAILED
  • Access: public

Parameters:

string   $dir   —  The directory to go to.

[ Top ]

checkFileExtension   [line 1398]

int checkFileExtension( string $filename)

This checks, whether a file should be transfered in ascii- or binary-mode by it's file-extension. If the file-extension is not set or the extension is not inside one of the extension-dirs, the actual set transfer-mode is returned.
  • Return: Either FTP_ASCII or FTP_BINARY
  • Access: public

Parameters:

string   $filename   —  The filename to be checked

[ Top ]

chmod   [line 834]

mixed chmod( mixed $target, integer $permissions)

This method will try to chmod the file specified on the server Currently, you must give a number as the the permission argument (777 or similar). The file can be either a relative or absolute path.

NOTE: Some servers do not support this feature. In that case, you will get a PEAR error object returned. If successful, the method returns true

  • Return: True if successful, otherwise PEAR::Error
  • See: NET_FTP_ERR_CHMOD_FAILED
  • Access: public

Parameters:

mixed   $target   —  The file or array of files to set permissions for
integer   $permissions   —  The mode to set the file permissions to

[ Top ]

chmodRecursive   [line 877]

mixed chmodRecursive( mixed $target, integer $permissions)

This method will try to chmod a folder and all of its contents on the server. The target argument must be a folder or an array of folders and the permissions argument have to be an integer (i.e. 777).

The file can be either a relative or absolute path. NOTE: Some servers do not support this feature. In that case, you will get a PEAR error object returned. If successful, the method returns true

  • Return: True if successful, otherwise PEAR::Error
  • See: NET_FTP_ERR_CHMOD_FAILED, NET_FTP_ERR_DETERMINEPATH_FAILED, NET_FTP_ERR_RAWDIRLIST_FAILED, NET_FTP_ERR_DIRLIST_UNSUPPORTED
  • Access: public

Parameters:

mixed   $target   —  The folder or array of folders to set permissions for
integer   $permissions   —  The mode to set the folder and file permissions to

[ Top ]

connect   [line 632]

mixed connect( [string $host = null], [int $port = null])

This function generates the FTP-connection. You can optionally define a hostname and/or a port. If you do so, this data is stored inside the object.
  • Return: True on success, otherwise PEAR::Error
  • See: NET_FTP_ERR_CONNECT_FAILED
  • Access: public

Parameters:

string   $host   —  (optional) The Hostname
int   $port   —  (optional) The Port

[ Top ]

detach   [line 1748]

boolean detach( object $observer)

Removes a Net_FTP_Observer instance from the list of observers.
  • Return: True if the observer is successfully detached.
  • Since: 1.3
  • Access: public

Parameters:

object   $observer   —  The Net_FTP_Observer instance to detach from the list of listeners.

[ Top ]

disconnect   [line 657]

bool|PEAR_Error disconnect( )

This function close the FTP-connection
  • Return: Returns true on success, PEAR_Error on failure
  • Access: public

[ Top ]

execute   [line 790]

mixed execute( string $command)

This method tries executing a command on the ftp, using SITE EXEC.
  • Return: The result of the command (if successfull), otherwise PEAR::Error
  • See: NET_FTP_ERR_EXEC_FAILED
  • Access: public

Parameters:

string   $command   —  The command to execute

[ Top ]

get   [line 1182]

mixed get( string $remote_file, string $local_file, [bool $overwrite = false], [int $mode = null])

This function will download a file from the ftp-server. You can either spcify a absolute

path to the file (beginning with "/") or a relative one, which will be completed with the actual directory you selected on the server. You can specify the path to which the file will be downloaded on the local maschine, if the file should be overwritten if it exists (optionally, default is no overwriting) and in which mode (FTP_ASCII or FTP_BINARY) the file should be downloaded (if you do not specify this, the method tries to determine it automatically from the mode-directory or uses the default-mode, set by you). If you give a relative path to the local-file, the script-path is used as basepath.

  • Return: True on success, otherwise PEAR::Error
  • See: NET_FTP_ERR_OVERWRITELOCALFILE_FORBIDDEN, NET_FTP_ERR_OVERWRITELOCALFILE_FAILED, NET_FTP_ERR_OVERWRITELOCALFILE_FAILED
  • Access: public

Parameters:

string   $remote_file   —  The absolute or relative path to the file to download
string   $local_file   —  The local file to put the downloaded in
bool   $overwrite   —  (optional) Whether to overwrite existing file
int   $mode   —  (optional) Either FTP_ASCII or FTP_BINARY

[ Top ]

getExtensionMode   [line 1699]

int getExtensionMode( string $ext)

Returns the mode set for a file-extension
  • Return: Either FTP_ASCII, FTP_BINARY or NULL (if not set a mode for it)
  • Access: public

Parameters:

string   $ext   —  The extension you wanna ask for

[ Top ]

getExtensionsFile   [line 1605]

mixed getExtensionsFile( string $filename)

This get's both (ascii- and binary-mode-directories) from the given file.

Beware, if you read a file into the mode-directory, all former set values will be unset!

  • Return: True on success, otherwise PEAR::Error
  • See: NET_FTP_ERR_EXTFILENOTEXIST, NET_FTP_ERR_EXTFILEREAD_FAILED
  • Access: public

Parameters:

string   $filename   —  The file to get from

[ Top ]

getHostname   [line 1626]

string getHostname( )

Returns the Hostname
  • Return: The Hostname
  • Access: public

[ Top ]

getMode   [line 1674]

int getMode( )

Returns the Transfermode
  • Return: The transfermode, either FTP_ASCII or FTP_BINARY.
  • Access: public

[ Top ]

getPassword   [line 1662]

string getPassword( )

Returns the Password
  • Return: The Password
  • Access: public

[ Top ]

getPort   [line 1638]

int getPort( )

Returns the Port
  • Return: The Port
  • Access: public

[ Top ]

getRecursive   [line 1286]

mixed getRecursive( string $remote_path, string $local_path, [bool $overwrite = false], [int $mode = null])

This functionality allows you to transfer a whole directory-structure from the remote-ftp to your local host. You have to give a remote-directory (ending with '/') and the local directory (ending with '/') where to put the files you download.

The remote path is automatically completed with the current-remote-dir, if you give a relative path to this function. You can give a relative path for the $local_path, too. Then the script-basedir will be used for comletion of the path. The parameter $overwrite will determine, whether to overwrite existing files or not. Standard for this is false. Fourth you can explicitly set a mode for all transfer- actions done. If you do not set this, the method tries to determine the transfer- mode by checking your mode-directory for the file-extension. If the extension is not inside the mode-directory, it will get your default-mode.

  • Return: True on succes, otherwise PEAR::Error
  • See: NET_FTP_ERR_OVERWRITELOCALFILE_FORBIDDEN, NET_FTP_ERR_OVERWRITELOCALFILE_FAILED, NET_FTP_ERR_OVERWRITELOCALFILE_FAILED, NET_FTP_ERR_REMOTEPATHNODIR, NET_FTP_ERR_LOCALPATHNODIR, NET_FTP_ERR_CREATELOCALDIR_FAILED
  • Access: public

Parameters:

string   $remote_path   —  The path to download
string   $local_path   —  The path to download to
bool   $overwrite   —  (optional) Whether to overwrite existing files (true) or not (false, standard).
int   $mode   —  (optional) The transfermode (either FTP_ASCII or FTP_BINARY).

[ Top ]

getTimeout   [line 1712]

int getTimeout( )

Get the currently set timeout.

Returns the actual timeout set.

  • Return: The actual timeout
  • Access: public

[ Top ]

getUsername   [line 1650]

string getUsername( )

Returns the Username
  • Return: The Username
  • Access: public

[ Top ]

isPassive   [line 1686]

bool isPassive( )

Returns, whether the connection is set to passive mode or not
  • Return: True if passive-, false if active-mode
  • Access: public

[ Top ]

login   [line 678]

mixed login( [string $username = null], [string $password = null])

This logges you into the ftp-server. You are free to specify username and password in this method. If you specify it, the values will be taken into the corresponding attributes, if do not specify, the attributes are taken.
  • Return: True on success, otherwise PEAR::Error
  • See: NET_FTP_ERR_LOGIN_FAILED
  • Access: public

Parameters:

string   $username   —  (optional) The username to use
string   $password   —  (optional) The password to use

[ Top ]

ls   [line 1099]

mixed ls( [string $dir = null], [int $mode = NET_FTP_DIRS_FILES])

This method returns a directory-list of the current directory or given one.

To display the current selected directory, simply set the first parameter to null or leave it blank, if you do not want to use any other parameters.

There are 4 different modes of listing directories. Either to list only the files (using NET_FTP_FILES_ONLY), to list only directories (using NET_FTP_DIRS_ONLY) or to show both (using NET_FTP_DIRS_FILES, which is default).

The 4th one is the NET_FTP_RAWLIST, which returns just the array created by the ftp_rawlist()-function build into PHP.

The other function-modes will return an array containing the requested data. The files and dirs are listed in human-sorted order, but if you select NET_FTP_DIRS_FILES the directories will be added above the files, but although both sorted.

All elements in the arrays are associative arrays themselves. The have the following structure:

Dirs:
["name"] => string The name of the directory
["rights"] => string The rights of the directory (in style "rwxr-xr-x")
["user"] => string The owner of the directory
["group"] => string The group-owner of the directory
["files_inside"]=> string The number of files/dirs inside the directory excluding "." and ".."
["date"] => int The creation-date as Unix timestamp
["is_dir"] => bool true, cause this is a dir


Files:
["name"] => string The name of the file
["size"] => int Size in bytes
["rights"] => string The rights of the file (in style "rwxr-xr-x")
["user"] => string The owner of the file
["group"] => string The group-owner of the file
["date"] => int The creation-date as Unix timestamp
["is_dir"] => bool false, cause this is a file

  • Return: The directory list as described above or PEAR::Error on failure.
  • See: NET_FTP_DIRS_FILES, NET_FTP_DIRS_ONLY, NET_FTP_FILES_ONLY, NET_FTP_RAWLIST, NET_FTP_ERR_DETERMINEPATH_FAILED, NET_FTP_ERR_RAWDIRLIST_FAILED, NET_FTP_ERR_DIRLIST_UNSUPPORTED
  • Access: public

Parameters:

string   $dir   —  (optional) The directory to list or null, when listing the current directory.
int   $mode   —  (optional) The mode which types to list (files, directories or both).

[ Top ]

mdtm   [line 1013]

mixed mdtm( string $file, [string $format = null])

This will return the last modification-time of a file. You can either give this function a relative or an absolute path to the file to check.

NOTE: Some servers will not support this feature and the function works only on files, not directories! When successful, it will return the last modification-time as a unix-timestamp or, when $format is specified, a preformated timestring.

  • Return: Unix timestamp, a preformated date-string or PEAR::Error
  • See: NET_FTP_ERR_MDTMDIR_UNSUPPORTED, NET_FTP_ERR_MDTM_FAILED, NET_FTP_ERR_DATEFORMAT_FAILED
  • Access: public

Parameters:

string   $file   —  The file to check
string   $format   —  (optional) The format to give the date back if not set, it will return a Unix timestamp

[ Top ]

mkdir   [line 752]

mixed mkdir( string $dir, [bool $recursive = false])

This works similar to the mkdir-command on your local machine. You can either give it an absolute or relative path. The relative path will be completed with the actual selected server-path. (see: pwd())
  • Return: True on success, otherwise PEAR::Error
  • See: NET_FTP_ERR_CREATEDIR_FAILED
  • Access: public

Parameters:

string   $dir   —  Absolute or relative dir-path
bool   $recursive   —  (optional) Create all needed directories

[ Top ]

put   [line 1233]

mixed put( string $local_file, string $remote_file, [bool $overwrite = false], [int $mode = null])

This function will upload a file to the ftp-server. You can either specify a absolute

path to the remote-file (beginning with "/") or a relative one, which will be completed with the actual directory you selected on the server. You can specify the path from which the file will be uploaded on the local maschine, if the file should be overwritten if it exists (optionally, default is no overwriting) and in which mode (FTP_ASCII or FTP_BINARY) the file should be downloaded (if you do not specify this, the method tries to determine it automatically from the mode-directory or uses the default-mode, set by you). If you give a relative path to the local-file, the script-path is used as basepath.

  • Return: True on success, otherwise PEAR::Error
  • See: NET_FTP_ERR_LOCALFILENOTEXIST, NET_FTP_ERR_OVERWRITEREMOTEFILE_FORBIDDEN, NET_FTP_ERR_UPLOADFILE_FAILED
  • Access: public

Parameters:

string   $local_file   —  The local file to upload
string   $remote_file   —  The absolute or relative path to the file to upload to
bool   $overwrite   —  (optional) Whether to overwrite existing file
int   $mode   —  (optional) Either FTP_ASCII or FTP_BINARY

[ Top ]

putRecursive   [line 1349]

mixed putRecursive( string $local_path, string $remote_path, [bool $overwrite = false], [int $mode = null])

This functionality allows you to transfer a whole directory-structure from your local host to the remote-ftp. You have to give a remote-directory (ending with '/') and the local directory (ending with '/') where to put the files you download.

The remote path is automatically completed with the current-remote-dir, if you give a relative path to this function. You can give a relative path for the $local_path, too. Then the script-basedir will be used for comletion of the path. The parameter $overwrite will determine, whether to overwrite existing files or not. Standard for this is false. Fourth you can explicitly set a mode for all transfer- actions done. If you do not set this, the method tries to determine the transfer- mode by checking your mode-directory for the file-extension. If the extension is not inside the mode-directory, it will get your default-mode.

  • Return: True on succes, otherwise PEAR::Error
  • See: NET_FTP_ERR_LOCALFILENOTEXIST, NET_FTP_ERR_OVERWRITEREMOTEFILE_FORBIDDEN, NET_FTP_ERR_UPLOADFILE_FAILED, NET_FTP_ERR_LOCALPATHNODIR, NET_FTP_ERR_REMOTEPATHNODIR
  • Access: public

Parameters:

string   $remote_path   —  The path to download
string   $local_path   —  The path to download to
bool   $overwrite   —  (optional) Whether to overwrite existing files (true) or not (false, standard).
int   $mode   —  (optional) The transfermode (either FTP_ASCII or FTP_BINARY).

[ Top ]

pwd   [line 730]

mixed pwd( )

Show's you the actual path on the server This function questions the ftp-handle for the actual selected path and returns it.
  • Return: The actual path or PEAR::Error
  • See: NET_FTP_ERR_DETERMINEPATH_FAILED
  • Access: public

[ Top ]

removeExtension   [line 1589]

void removeExtension( string $ext)

This function removes an extension from the mode-directories (described above).
  • Access: public

Parameters:

string   $ext   —  The extension to remove

[ Top ]

rename   [line 966]

bool rename( string $remote_from, string $remote_to)

Rename or move a file or a directory from the ftp-server
  • Return: True on success, otherwise PEAR::Error
  • See: NET_FTP_ERR_RENAME_FAILED
  • Access: public

Parameters:

string   $remote_from   —  The remote file or directory original to rename or move
string   $remote_to   —  The remote file or directory final to rename or move

[ Top ]

rm   [line 1147]

mixed rm( string $path, [bool $recursive = false])

This method will delete the given file or directory ($path) from the server (maybe recursive).

Whether the given string is a file or directory is only determined by the last sign inside the string ("/" or not).

If you specify a directory, you can optionally specify $recursive as true, to let the directory be deleted recursive (with all sub-directories and files inherited).

You can either give a absolute or relative path for the file / dir. If you choose to use the relative path, it will be automatically completed with the actual selected directory.

  • Return: True on success, otherwise PEAR::Error
  • See: NET_FTP_ERR_DELETEFILE_FAILED, NET_FTP_ERR_DELETEDIR_FAILED, NET_FTP_ERR_REMOTEPATHNODIR
  • Access: public

Parameters:

string   $path   —  The absolute or relative path to the file / directory.
bool   $recursive   —  (optional)

[ Top ]

setActive   [line 1525]

void setActive( )

Set the transfer-method to active mode
  • Access: public

[ Top ]

setHostname   [line 1424]

bool setHostname( string $host)

Set the Hostname
  • Return: True on success, otherwise PEAR::Error
  • See: NET_FTP_ERR_HOSTNAMENOSTRING
  • Access: public

Parameters:

string   $host   —  The Hostname to set

[ Top ]

setMode   [line 1495]

mixed setMode( int $mode)

Set the transfer-mode. You can use the predefined constants FTP_ASCII or FTP_BINARY. The mode will be stored for any further transfers.
  • Return: True on success, otherwise PEAR::Error
  • See: NET_FTP_ERR_NOMODECONST
  • Access: public

Parameters:

int   $mode   —  The mode to set

[ Top ]

setPassive   [line 1512]

void setPassive( )

Set the transfer-method to passive mode
  • Access: public

[ Top ]

setPort   [line 1442]

bool setPort( int $port)

Set the Port
  • Return: True on success, otherwise PEAR::Error
  • See: NET_FTP_ERR_PORTLESSZERO
  • Access: public

Parameters:

int   $port   —  The Port to set

[ Top ]

setTimeout   [line 1541]

bool setTimeout( [int $timeout = 0])

Set the timeout for FTP operations Use this method to set a timeout for FTP operation. Timeout has to be an integer.
  • Return: True on success, otherwise PEAR::Error
  • See: NET_FTP_ERR_TIMEOUTLESSZERO, NET_FTP_ERR_SETTIMEOUT_FAILED

Parameters:

int   $timeout   —  the timeout to use

[ Top ]

setUsername   [line 1460]

mixed setUsername( string $user)

Set the Username
  • Return: True on success, otherwise PEAR::Error
  • See: NET_FTP_ERR_USERNAMENOSTRING
  • Access: public

Parameters:

string   $user   —  The Username to set

[ Top ]

site   [line 810]

mixed site( string $command)

Execute a SITE command on the server This method tries to execute a SITE command on the ftp server.
  • Return: True if successful, otherwise PEAR::Error
  • See: NET_FTP_ERR_SITE_FAILED
  • Access: public

Parameters:

string   $command   —  The command with parameters to execute

[ Top ]

size   [line 1042]

mixed size( string $file)

This will return the size of a given file in bytes. You can either give this function a relative or an absolute file-path. NOTE: Some servers do not support this feature!
  • Return: Size in bytes or PEAR::Error
  • See: NET_FTP_ERR_SIZE_FAILED
  • Access: public

Parameters:

string   $file   —  The file to check

[ Top ]


Documentation generated on Mon, 11 Mar 2019 13:55:48 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.