Welcome Guest, Not a member yet? Register   Sign In
Improved FTP Class
#1

[eluser]Phil Sturgeon[/eluser]
I recently made a class takes config "groups" just like the database config. I used this as I wanted to be able to connect to various different servers within the same file without having to enter the config arrays many times.

/application/config/Ftp.php

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| FTP
| -------------------------------------------------------------------
| This file contains connection details for your sites FTP server.
| This is used for uploading of large files (over 2 megs) to stop
| the timing out of upload sessions.
|
| Please see user guide for more info:
| http://www.ellislab.com/codeigniter/user-guide/libraries/ftp.html
|
*/

$active_group = "default";

$ftp['default']['hostname'] = 'somesite.com';
$ftp['default']['username'] = 'bobby';
$ftp['default']['password'] = 'password';
$ftp['default']['port']     = 21;
$ftp['default']['passive']  = FALSE;
$ftp['default']['debug']    = TRUE;
$ftp['default']['ssl_mode'] = FALSE;

$ftp['media_server']['hostname'] = 'otherhost.com';
$ftp['media_server']['username'] = 'mcdoogle';
$ftp['media_server']['password'] = 'secret';
$ftp['media_server']['port']     = 21;
$ftp['media_server']['passive']  = FALSE;
$ftp['media_server']['debug']    = TRUE;
$ftp['media_server']['ssl_mode'] = FALSE;


?>

/application/libraries/MY_Ftp.php
Code on Pastebin for now

The benefits of this are that it can be used EXACTLY like the old FTP library, with some added usefulness with the multiple connection types, and obviously saves on repeated code. You can pass it custom config variables, or simply the name of one of your groups like so:

Code:
$this->ftp->connect('media_server');                        $this->ftp->move('public_html/local/file.png', 'public_html/remote/file.png');
$this->ftp->close();

It also supports FTP SSL connections. For error messages to be able to show, you will need to add the line below to your ftp lang file.

Code:
// Custom
$lang['ftp_ssl_not_supported']        = "Unable to connect to the server using SSL.";

Please test it and let me know how it goes. If it works ok then i'll put it on the Wiki.


Messages In This Thread
Improved FTP Class - by El Forum - 07-29-2007, 10:30 AM
Improved FTP Class - by El Forum - 07-29-2007, 11:10 AM
Improved FTP Class - by El Forum - 07-30-2007, 03:40 AM
Improved FTP Class - by El Forum - 08-04-2007, 01:17 PM
Improved FTP Class - by El Forum - 10-10-2008, 04:57 PM
Improved FTP Class - by El Forum - 01-08-2009, 07:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB