WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : very simple ftp class
Categories : PHP, PHP Classes, FTP Click here to Update Your Picture
buboy martinez
Date : Aug 09th 2006
Grade : 4 of 5 (graded 2 times)
Viewed : 23865
File : 4475.php
Images : No Images for this code example.
Search : More code by buboy martinez
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

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.

<?php

/*
    PHP_FTP
    Version 0.5
    Ryan Flynn (ryan@ryanflynn || DALnet->#php->pizza_milkshake)
    Tuesday, June 26 2001
   
    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='', $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);
                        echo $this->remote_dir.$filename;
                        return false;
                    }else{
                        @ftp_quit($this->conn);
                        return true;
                    }
            }
*/           
           
function get($filename='', $save_as='', $passive=TRUE){
               
               
$handle = fopen($save_as, 'w');
               
               
$conn=$this->return_connection() or die;
                @
ftp_pasv($conn, $passive);
               
$this->set_remote_dir(ftp_pwd($conn));
                    if(!
ftp_nb_fget($conn, $handle, $this->remote_dir.$filename, FTP_ASCII, 0)){
                        @
ftp_quit($this->conn);
                        echo
$this->remote_dir.$filename;
                        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;
            }
    }
?>


Usage Example - Get a file
<?php
   
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
?>           


Usage Example - Send a file
<?php
   
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();
?>


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



Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support
Categories : PHP, FTP, Filesystem, PHP Classes, Compression
credit card security code
Categories : PHP, Credit Cards, PHP Classes, Credit Cards
Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip
Categories : Email, Network, PHP, PHP Classes
Inline Scope Control - The inline class provides methods for creating and destroying local variable scopes. Simply put, local scopes are spaces where some or all of the global variables are temporarily hidden.
Categories : PHP, PHP Classes, Variables
TableMaint: class to help in the updating of data stored in database tables
Categories : PHP, PHP Classes, Databases
Compare two texts and display a block of text with the differences between them.
Categories : PHP, PHP Classes, Filesystem, Strings, Arrays
Linkers Class
Categories : PHP Classes, PHP
O-LOC : PHP 5.x Internationalization class and back-office. manage the display of translations on a localized web application.
Categories : PHP, PHP Classes, Web Applications, Languages, DOM XML
Db_lib - practical example usage of database abstraction and form validation.
Categories : PHP, Form Processing, PHP Classes, Data Validation, Beginner Guides
XML To Array
Categories : PHP, PHP Classes, XML, Arrays
imageMarker v 3.00 with new advanced features
Categories : PHP, PHP Classes, Graphics, GD image library
an example of the cyberlib payment class
Categories : PHP, PHP Classes, Ecommerce, Credit Cards
pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes
PHP5 SQLite Abstraction class
Categories : PHP, PHP Classes, SQLite, Databases
A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Categories : PHP, PHP Classes, Calendar, Date Time
 Bruce Somers wrote :1655
"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."

There is a function kill() in PHP? How infantile it would be.