JFTP

From Joomla! Documentation

Jump to: navigation, search

JFTP is an FTP client class, that allows you to connect and interact with an FTP server.

Contents

Availability

From Joomla 1.5 Joomla 1.6

Defined in

/libraries/joomla/client/ftp.php

Extends

Methods

Method name Description
__construct Constructor. Set's transfer type and other options.
__destruct Destructor. Makes sure the FTP server connection is closed at the end of script.
chdir Changes the current working directory on the FTP server.
chmod Changes the mode for a path on the FTP server.
connect Connects the object to a FTP server.
create Creates an empty file on the FTP server.
delete Deletes a path(file/folder) on the FTP server.
get Gets a file from the FTP server and saves it to a given local file.
getInstance Returns a reference to the global FTP connector object, only creating it, if it doesn't already exist.
isConnected Determines if the object is connected to an FTP server
listDetails Lists the contents of a directory on the FTP server
listNames Lists the filenames of the contents of a directory on the FTP server
login Login to a server once connected
mkdir Creates a directory on the FTP server
pwd Retrieves the current working directory on the FTP server
quit Quits and closes the connection
read Reads a file from the FTP server's contents into a buffer
reinit Reinitializes the server, i.e. logs in again.
rename Renames a file/folder on the FTP server
restart Restarts data transfer at a given byte.
setOptions Sets options of this FTP client object
store Stores a file to the FTP server
syst Gets the system identifier string from the FTP server
write Writes a string to a certain file on the FTP server.

Importing

jimport( 'joomla.client.ftp' );

See also

Examples

$host = 'joomla.org';
$port = 21;
$options = null;
$user = 'randomUserName';
$pass = 'thisIsDefinatlyNotThePassword';
 
jimport('joomla.client.ftp');
 
/*
 * The JFTP::getInstance() method will connect us to the FTP server and automatically
 * log us in. We could do the same with the connect() and login() methods. Also check 
 * out JClientHelper::getCredentials('ftp');
 */
 
$ftp = JFTP::getInstance($host, $port, $options, $user, $pass);
 
if($ftp->isConnected()){
   //We are connected.
 
   //Let's print the details of the root directory
   echo '<pre>';
   print_r($ftp->listDetails());
   echo '</pre>';
 
   /* Assuming we only have one "Joomla" directory, this would look like this.
   Array
   (
    [0] => Array
        (
            [type] => 1
            [rights] => drwxr-xr-x
            [user] => randomUserName
            [group] => ftpusers
            [size] => 4096
            [date] => 03-15
            [time] => 2008
            [name] => Joomla
        )
   )
   */
   //Let's create a directory
   $ftp->mkdir('test');
 
   //Let's create a file in that new directory
   $ftp->create('test/fairyTale.txt');
 
   //Let's write the first line of our Fairy Tale into our newly created text file
   $ftp->write('test/fairyTale.txt', 'Once upon a time, there was a litte Mermaid, called Arielle');
 
   //Let's read the fairy tale out of the file, and echo it out.
   $fairyTale = '';
   $ftp->read('test/fairyTale.txt', $fairyTale);
   echo $fairyTale;
 
   //Let's think of a name for our fairyTale, and rename the file
   $ftp->rename('test/fairyTale.txt', 'test/Arielle.txt');
 
   //I think you got the idea =)
}
Retrieved from "http://docs.joomla.org/JFTP"
Personal tools