PHP
  Home arrow PHP arrow Page 6 - My FTP Wrapper Class for PHP
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

My FTP Wrapper Class for PHP
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 20
    2003-02-21

    Table of Contents:
  • My FTP Wrapper Class for PHP
  • Wrapping? Huh?
  • Functions, Functions and More Functions!
  • The Functions (contd.)
  • The Functions (contd.)
  • Examples of Using the MY_FTP Class
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    My FTP Wrapper Class for PHP - Examples of Using the MY_FTP Class


    (Page 6 of 7 )

    OK, so now you know the basics of what each function does. Notice that I didn’t go into too much detail about that actual code? That’s because I think that you really need to play around with it to really understand it. It shouldn’t take you more than about 1 hour to fully come to grips with the code, because I’ve included comments where appropriate.

    Example #1: Getting a List of Files
    This example connects to Microsoft’s FTP server and grabs a list of files in the /Services/enterprise directory, outputting the filename and file size for files, and just the directory name for directories:

    <?php

    require_once("class.myftp.php");

    $err = "";
    $fileList = array();
    $ftpClass = new MY_FTP;

    $ftpClass->Connect("ftp.microsoft.com", "anonymous", "someone@somewhere.com", "/", $err);
    $fileList = @$ftpClass->GetFileListAsArray("/Services/enterprise", $err);

    if($err == "")
    {
    for($i = 0; $i < sizeof($fileList); $i++)
    {
    if($fileList[$i]["type"] == 0) // Folder
    echo $fileList[$i]["filename"] . " (directory)<br>";
    else // File
    echo $fileList[$i]["filename"] . " (" . $fileList[$i]["filesize"] . " bytes)<br>";
    }
    }
    else
    {
    echo $err;
    }

    ?>


    Example #2: Getting the Contents of a File
    Again, this example uses Micrososft’s FTP server to grab the contents of a file called readme.txt and outputs it to the browser:

    <?php

    require_once("class.myftp.php");

    $err = "";
    $fileList = array();
    $ftpClass = new MY_FTP;

    $ftpClass->Connect("ftp.microsoft.com", "anonymous", "someone@somewhere.com", "/", $err);
    $readMe = $ftpClass->RetrieveDataFromRemoteFile("readme.txt", "/developr", $err);

    if($err == "")
    {
    echo "<h1>Readme.txt</h1>";
    echo $readMe;
    }
    else
    {
    echo $err;
    }

    ?>


    Example #3: Does a File Exist?
    This example checks if a file called Desktop.exe exists in the /Services/enterprise directory of the Microsoft FTP server:

    <?php

    require_once("class.myftp.php");

    $err = "";
    $fileList = array();
    $ftpClass = new MY_FTP;

    $ftpClass->Connect("ftp.microsoft.com", "anonymous", "someone@somewhere.com", "/", $err);
    $exists = $ftpClass->DoesFileExist("/Services/enterprise", "Desktop.exe", $err);

    if($err == "")
    {
    if($exists)
    echo "Desktop.exe exists in /Services/enterprise";
    else
    echo "Desktop.exe doesn't exist in /Services/enterprise";
    }
    else
    {
    echo $err;
    }

    ?>

    More PHP Articles
    More By Mitchell Harper


       · Ive been toying with the idea of writing an FTP class too, so Im glad someone else...
     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway