Miscellaneous Code
  Home arrow Miscellaneous Code arrow PHP_FTP
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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? 
MISCELLANEOUS CODE

PHP_FTP
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-01-18

    Table of Contents:

    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


    Alot of people have asked for VERY simple FTP functionality with PHP, so here it is. This class was designed with very simplistic transfers in mind. You simple create the class, get/send a file and then 'kill()' the object. It's that simple. I you find it useful.

    By : ryanflynn

    <?php

    /*
    PHP_FTP
    Version 0.5
    Ryan Flynn (ryan@ryanflynn || DALnet->#php->pizza_milkshake)
    Tuesday, June 26 2001

    Alot of people have asked for VERY simple FTP functionality with PHP, so here it is.
    This class was designed with very simplistic transfers in mind. You simple create the class,
    get/send a file and then 'kill()' the object. It's that simple. I you find it useful.

    Example:

    //Get a file
    require("class.ftp.php"); //include library
    $f=new PHP_FTP('ftp.somesite.com', 'username', 'password'); //specify connect info
    $f->get('html/test.txt', 'c:/php/ftp/blah.txt'); //yes, tested on Windows
    $f->kill(); //optional destroy class method

    //Send a file
    require("class.ftp.php");
    $f=new PHP_FTP('ftp.somesite.com', 'username', 'password', 21); //optional port as 4th arg
    $f->send('c:/php/ftp/blah.txt', 'html/test.txt'); //yes, tested on Windows
    $f->kill();

    //how to test for completion
    if(!$f->send('c:/php/ftp/blah.txt', 'html/test.txt')){
    echo "File sent successfully!";
    }else{
    echo "Error sending file.";
    }

    Notes:
    Remember to have all permissions set to their appropriate settings before using
    this class
    */


    class PHP_FTP{

    var $server='';
    var $username='';
    var $password='';
    var $port=21;
    var $remote_dir='';

    function PHP_FTP($server, $username='anonymous', $password='e@mail.com', $port=21){
    $this->server=$server;
    $this->username=$username;
    $this->password=$password;
    $this->port=$port;
    }

    //exterior

    function send($filename='', $save_as='', $passive=TRUE){
    $conn=$this->return_connection() or die;
    @ftp_pasv($conn, $passive);
    $this->set_remote_dir(ftp_pwd($conn));
    if(!ftp_put($conn, $save_as, $filename, FTP_BINARY)){
    @ftp_quit($this->conn);
    return false;
    }else{
    @ftp_quit($this->conn);
    return true;
    }
    return true;
    }

    function get($filename='', $save_as='', $passive=TRUE){
    $conn=$this->return_connection() or die;
    @ftp_pasv($conn, $passive);
    $this->set_remote_dir(ftp_pwd($conn));
    if(!ftp_get($conn, $save_as, $this->remote_dir.$filename, FTP_BINARY)){
    @ftp_quit($this->conn);
    return false;
    }else{
    @ftp_quit($this->conn);
    return true;
    }
    }

    function kill(){
    if($this->conn)
    $this->disconnect();
    unset($this);
    }

    //interior
    function return_connection(){
    $conn_id = @ftp_connect($this->server, $this->port) or die("Could not connect to FTP");
    $login_result = @ftp_login($conn_id, $this->username, $this->password) or die("Could not login to FTP");
    return $conn_id;
    }

    function set_remote_dir($dir){
    $x = substr($dir, (strlen($dir)-1));
    if($x != "/" && $x != "\\")
    $dir.="/";
    $this->remote_dir=$dir;
    }
    }
    ?>

    /* example */

    require("class.ftp.php");
    $f=new PHP_FTP('ftp.somesite.com', 'username', 'password', 21); //optional port as 4th arg
    $f->send('c:/php/ftp/blah.txt', 'html/test.txt'); //yes, tested on Windows
    $f->kill();
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Achieving True Agility -- How process can change the behavior of your tools

    Achieving true agility is a never-ending effort. We will showcase how you can become agile incrementally, a few practices at the time.Which practices should any agile team strive to adopt? What additional practices should you consider based on your needs to scale? Adopting practices are however made much easier with the right tool support. What about if your tools adapt to your practices? We will take a look at how the Jazz technology can be leveraged to make your process change the behavior of your tools.
    FREE! Go There Now!


    NEW! Hello World: Monitor a simple business process using WebSphere Business Monitor V6.0.2

    This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product.
    FREE! Go There Now!


    NEW! Innovate don't duplicate! Asset reuse strategies for success

    Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository.
    FREE! Go There Now!


    NEW! Rational Modeling Extension for Microsoft.Net

    Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms.
    FREE! Go There Now!


    NEW! Rational Talks to You:Per Kroll on Rational Method Composer Plug-in customization

    Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered!
    FREE! Go There Now!


    NEW! Test terminal-based applications with Rational Functional Tester

    Regression testing -- in which code is thoroughly tested to ensure that changes have not produced unexpected results -- is an important part of any development process. But many testing environments neglect the terminal-based applications that still form the backbone of many industries. In this tutorial, you'll learn how the Rational Functional Tester Extension for Terminal-Based Applications works with other Rational Functional Tester to help test terminal-based applications quickly and easily.
    FREE! Go There Now!


    NEW! Trial download: IBM Informix Dynamic Server Express Edition V11.0

    Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Connectivity

    Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic.
    FREE! Go There Now!


    NEW! Webcast: Accelerating Software Innovation with System z

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Webcast: Calling All Testers! Find Application Vulnerabilities Early in the Development Process Where they are Easier to Fix and Less Risky to your Business

    In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...
    - Model Data and Validation Rules for a Generi...
    - Building a Generic Model for the CodeIgniter...
    - upload image to database sql
    - Random Password Generator
    - BCroot, get the root of a number with BC fun...
    - Find pi in a high precision
    - [PHP5] FORMCHECKER : data validation
    - SPL and ITERATOR : examples
    - Xml with Rss Feeds





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 12 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek