Esempio n. 1
0
File: Chmod.php Progetto: robik/cFTP
  *     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 );
Esempio n. 2
0
  *     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' ";
Esempio n. 3
0
  *     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
Esempio n. 4
0
  *     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/>';
 }
Esempio n. 5
0
  * 
  * @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 )
     {
Esempio n. 6
0
  *     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