PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/halogy/application/libraries/MY_Ftp.php

https://bitbucket.org/haloweb/halogy-1.0/
PHP | 92 lines | 39 code | 10 blank | 43 comment | 11 complexity | cf0a2436b93e727f3aae5cbae34b8602 MD5 | raw file
 1<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 2/**
 3 * CodeIgniter
 4 *
 5 * An open source application development framework for PHP 4.3.2 or newer
 6 *
 7 * @package		CodeIgniter
 8 * @author		ExpressionEngine Dev Team
 9 * @copyright	Copyright (c) 2008, EllisLab, Inc.
10 * @license		http://codeigniter.com/user_guide/license.html
11 * @link		http://codeigniter.com
12 * @since		Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * FTP Class
20 *
21 * @package		CodeIgniter
22 * @subpackage	Libraries
23 * @category	Libraries
24 * @author		ExpressionEngine Dev Team
25 * @link		http://codeigniter.com/user_guide/libraries/ftp.html
26 */ 
27class MY_FTP extends CI_FTP {
28	
29	/**
30	 * Read a directory and recreate it remotely
31	 *
32	 * This function recursively reads a folder and everything it contains (including
33	 * sub-folders) and creates a mirror via FTP based on it.  Whatever the directory structure
34	 * of the original file path will be recreated on the server.
35	 *
36	 * @access	public
37	 * @param	string	path to source with trailing slash
38	 * @param	string	path to destination - include the base folder with trailing slash
39	 * @return	bool
40	 */	
41	function mirror($locpath, $rempath)
42	{
43		if ( ! $this->_is_conn())
44		{
45			return FALSE;
46		}
47
48		// Open the local file path
49		if ($fp = @opendir($locpath))
50		{
51			// Attempt to open the remote file path.
52			if ( ! $this->changedir($rempath, TRUE))
53			{
54				// If it doesn't exist we'll attempt to create the direcotory
55				if ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath))
56				{
57					return FALSE;
58				}
59			}
60		
61			// Recursively read the local directory
62			while (FALSE !== ($file = readdir($fp)))
63			{
64				if (@is_dir($locpath.$file) && substr($file, 0, 1) != '.')
65				{					
66					$this->mirror($locpath.$file."/", $rempath.$file."/");
67				}
68				elseif ($file == ".htaccess")
69				{
70					$this->upload($locpath.$file, $rempath.$file, 'ascii');
71				}
72				elseif (substr($file, 0, 1) != ".")
73				{
74					// Get the file extension so we can se the upload type
75					$ext = $this->_getext($file);
76					$mode = $this->_settype($ext);
77					
78					$this->upload($locpath.$file, $rempath.$file, $mode);
79				}
80			}
81			return TRUE;
82		}
83		
84		return FALSE;
85	}
86
87
88}
89// END FTP Class
90
91/* End of file Ftp.php */
92/* Location: ./system/libraries/Ftp.php */