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

Class: Net_FTP

Source Location: /Net_FTP-1.4.0a2/Net/FTP.php

Class Overview

PEAR
   |
   --Net_FTP

Class for comfortable FTP-communication


Author(s):

Version:

  • Release: 1.4.0a2

Copyright:

  • 1997-2008 The PHP Group

Methods


Inherited Variables

Inherited Methods


Class Details

[line 552]
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 685]

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.


Parameters:

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

[ Top ]

addExtension   [line 1830]

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 2007]

boolean attach( 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.

[ Top ]

cd   [line 829]

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").

Parameters:

string   $dir     The directory to go to.

[ Top ]

checkFileExtension   [line 1646]

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 969]

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


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 1014]

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


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 737]

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.

Parameters:

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

[ Top ]

detach   [line 2027]

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 764]

bool|PEAR_Error disconnect( )

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

[ Top ]

execute   [line 923]

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 1355]

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 specify an 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 machine, 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.


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 1979]

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 1870]

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!

Example file contents: [ASCII] asc = 0 txt = 0 [BINARY] bin = 1 jpg = 1


Parameters:

string   $filename     The file to get from

[ Top ]

getHostname   [line 1911]

string getHostname( )

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

[ Top ]

getMode   [line 1955]

int getMode( )

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

[ Top ]

getPassword   [line 1944]

string getPassword( )

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

[ Top ]

getPort   [line 1922]

int getPort( )

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

[ Top ]

getRecursive   [line 1504]

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.

Since 1.4 no error will be returned when a file exists while $overwrite is set to false.


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 1991]

int getTimeout( )

Get the currently set timeout.

Returns the actual timeout set.

  • Return: The actual timeout
  • Access: public

[ Top ]

getUsername   [line 1933]

string getUsername( )

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

[ Top ]

isPassive   [line 1966]

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 789]

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

This logs 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.

If connect() has not been called yet, a connection will be setup


Parameters:

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

[ Top ]

ls   [line 1259]

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


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 1160]

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.


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 872]

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())

Parameters:

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

[ Top ]

put   [line 1422]

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

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.


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
int   $options     (optional) Flags describing the behaviour of this function. Currently NET_FTP_BLOCKING and NET_FTP_NONBLOCKING are supported, of which NET_FTP_NONBLOCKING is the default.

[ Top ]

putRecursive   [line 1589]

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.


Parameters:

string   $local_path     The path to download to
string   $remote_path     The path to download
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 849]

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.

[ Top ]

removeExtension   [line 1844]

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 1108]

bool rename( string $remote_from, string $remote_to)

Rename or move a file or a directory from the ftp-server

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 1316]

mixed rm( string $path, [bool $recursive = false], [bool $filesonly = 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.


Parameters:

string   $path     The absolute or relative path to the file/directory.
bool   $recursive     Recursively delete everything in $path
bool   $filesonly     When deleting recursively, only delete files so the directory structure is preserved

[ Top ]

setActive   [line 1774]

void setActive( )

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

[ Top ]

setDirMatcher   [line 2075]

bool|PEAR_Error setDirMatcher( string $pattern, array $matchmap)

Sets the directory listing matcher

Use this method to set the directory listing matcher to a specific pattern. Indicate the pattern as a perl regular expression and give an array containing as keys the fields selected in the regular expression and as values the offset of the subpattern in the pattern.

Example: $pattern = '/(?:(d)|.)([rwxt-]+)\s+(\w+)\s+([\w\d-]+)\s+([\w\d-]+)\s+(\w+) \s+(\S+\s+\S+\s+\S+)\s+(.+)/', $matchmap = array( 'is_dir' => 1, 'rights' => 2, 'files_inside' => 3, 'user' => 4, 'group' => 5, 'size' => 6, 'date' => 7, 'name' => 8, )

Make sure at least the is_dir and name keys are set. The is_dir key should point to a subpattern that is empty for non-directories and non-empty for directories.

  • Return: True if matcher set successfully, PEAR_Error otherwise
  • See: NET_FTP_ERR_ILLEGALPATTERN, NET_FTP_ERR_ILLEGALMAP NET_FTP_ERR_ILLEGALMAPVALUE
  • Since: 1.4.0a1
  • Access: public

Parameters:

string   $pattern     The new matcher pattern to use
array   $matchmap     An mapping from key to subpattern offset

[ Top ]

setHostname   [line 1670]

bool setHostname( string $host)

Set the hostname

Parameters:

string   $host     The hostname to set

[ Top ]

setMode   [line 1745]

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.

Parameters:

int   $mode     The mode to set

[ Top ]

setPassive   [line 1762]

void setPassive( )

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

[ Top ]

setPort   [line 1689]

bool setPort( int $port)

Set the Port

Parameters:

int   $port     The port to set

[ Top ]

setTimeout   [line 1792]

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.


Parameters:

int   $timeout     the timeout to use

[ Top ]

setUsername   [line 1708]

mixed setUsername( string $user)

Set the Username

Parameters:

string   $user     The username to set

[ Top ]

site   [line 944]

mixed site( string $command)

Execute a SITE command on the server This method tries to execute a SITE command on the ftp server.

Parameters:

string   $command     The command with parameters to execute

[ Top ]

size   [line 1193]

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!

Parameters:

string   $file     The file to check

[ Top ]


Documentation generated on Mon, 19 May 2008 16:00:11 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.