* Change file mode * * @package Examples * @desc This example shows how to change file mode */ # Include cFTP_Autoloader include '../lib/cFTP/Autoload.php'; # Where to connect $ftp_host = 'ftp.mozilla.org'; # Some set-up $ftp_connection = new cFTP_Connection( $ftp_host ); $ftp = new cFTP_Session(); try { $ftp->connect($ftp_connection); # Login (default as anonymous) $ftp->login(); $root = $ftp->dir(); if( !$root->childExists('foo.txt') ) die("File doesn't exists"); # Create new Chmod helper $chmod = new cFTP_Chmod; $chmod->setEveryoneAccessMode( cFTP_Chmod::READ );
* Checking item existence in directory * * @package Examples * @desc This example checks existence of some directory */ # Include cFTP_Autoloader include '../lib/cFTP/Autoload.php'; # Where to connect $ftp_host = 'ftp.mozilla.org'; # Some set-up $ftp_connection = new cFTP_Connection( $ftp_host ); $ftp = new cFTP_Session($ftp_connection); # Login (default as anonymous) $ftp->login(); $root = $ftp->getDirectory(); $item = 'foo'; echo "Item '$item' "; echo $root->childExists($item) ? 'exists' : 'doesn\'t exists'; echo '<br />'; $item = 'pub'; echo "Item '$item' ";
* Listing items in directory * * @package Examples * @desc This example shows how to list items in directory */ # Include cFTP_Autoloader include '../lib/cFTP/Autoload.php'; # Where to connect $ftp_host = 'ftp.mozilla.org'; # Some set-up $ftp_connection = new cFTP_Connection( $ftp_host ); $ftp = new cFTP_Session(); # Connect $ftp->connect($ftp_connection); # Login (default as anonymous) $ftp->login(); # Loop items and print 'em $items = $ftp->dir('.')->listItems(); foreach( $items as $item ) { echo "<b>$item</b> found <br/>"; } # Close the connection
* Listing items in directory with detecting type * * @package Examples * @desc This example lists file with determining item type */ # Include cFTP_Autoloader include '../lib/cFTP/Autoload.php'; # Where to connect $ftp_host = 'ftp.mozilla.org'; # Some set-up $ftp_connection = new cFTP_Connection( $ftp_host ); $ftp = new cFTP_Session($ftp_connection); # Note the diffrent way to connect # Login (default as anonymous) $ftp->login(); $items = $ftp->dir('.')->listAdvanced(); foreach( $items as $item ) { if( $item instanceof cFTP_Directory ) echo 'Directory '; else echo 'File '; echo '<b>'.$item->getName().'</b> found <br/>'; }
* * @package Examples * @desc This example shows how to catch exceptions v2 */ # Include cFTP_Autoloader include '../lib/cFTP/Autoload.php'; # Where to connect # Mistake made intentionally $ftp_host = 'fttp.mozilla.org'; # Some set-up $ftp_connection = new cFTP_Connection( $ftp_host ); $ftp = new cFTP_Session(); try { $ftp->connect($ftp_connection); # Login (default as anonymous) $ftp->login(); # Close the connection $ftp->close(); } catch( cFTP_Exception $e) { if( $e->getCode() == cFTP_ExceptionCodes::Connect ) {
* Listing items in directory v2 * * @package Examples * @desc This example shows how to list items in directory using callback */ # Include cFTP_Autoloader include '../lib/cFTP/Autoload.php'; # Where to connect $ftp_host = 'ftp.mozilla.org'; # Some set-up $ftp_connection = new cFTP_Connection( $ftp_host ); $ftp = new cFTP_Session($ftp_connection); # Login (default as anonymous) $ftp->login(); # Following code is avaible only on PHP version > 5.3, # if you want to do same thing on PHP version lower than 5.3 use create_function() $items = $ftp->dir('.')->walk( function( cFTP_Item $e ) { echo '<b>'.$e->getName().'</b> found <br/>'; }); # Close the connection