/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. * FTP Class
  18. *
  19. * @package CodeIgniter
  20. * @subpackage Libraries
  21. * @category Libraries
  22. * @author ExpressionEngine Dev Team
  23. * @link http://codeigniter.com/user_guide/libraries/ftp.html
  24. */
  25. class MY_FTP extends CI_FTP {
  26. /**
  27. * Read a directory and recreate it remotely
  28. *
  29. * This function recursively reads a folder and everything it contains (including
  30. * sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure
  31. * of the original file path will be recreated on the server.
  32. *
  33. * @access public
  34. * @param string path to source with trailing slash
  35. * @param string path to destination - include the base folder with trailing slash
  36. * @return bool
  37. */
  38. function mirror($locpath, $rempath)
  39. {
  40. if ( ! $this->_is_conn())
  41. {
  42. return FALSE;
  43. }
  44. // Open the local file path
  45. if ($fp = @opendir($locpath))
  46. {
  47. // Attempt to open the remote file path.
  48. if ( ! $this->changedir($rempath, TRUE))
  49. {
  50. // If it doesn't exist we'll attempt to create the direcotory
  51. if ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath))
  52. {
  53. return FALSE;
  54. }
  55. }
  56. // Recursively read the local directory
  57. while (FALSE !== ($file = readdir($fp)))
  58. {
  59. if (@is_dir($locpath.$file) && substr($file, 0, 1) != '.')
  60. {
  61. $this->mirror($locpath.$file."/", $rempath.$file."/");
  62. }
  63. elseif ($file == ".htaccess")
  64. {
  65. $this->upload($locpath.$file, $rempath.$file, 'ascii');
  66. }
  67. elseif (substr($file, 0, 1) != ".")
  68. {
  69. // Get the file extension so we can se the upload type
  70. $ext = $this->_getext($file);
  71. $mode = $this->_settype($ext);
  72. $this->upload($locpath.$file, $rempath.$file, $mode);
  73. }
  74. }
  75. return TRUE;
  76. }
  77. return FALSE;
  78. }
  79. }
  80. // END FTP Class
  81. /* End of file Ftp.php */
  82. /* Location: ./system/libraries/Ftp.php */