summaryrefslogtreecommitdiffstats
path: root/system/libraries/Ftp.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Ftp.php')
-rw-r--r--system/libraries/Ftp.php118
1 files changed, 56 insertions, 62 deletions
diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php
index d7a8b3b02..ab395b0a0 100644
--- a/system/libraries/Ftp.php
+++ b/system/libraries/Ftp.php
@@ -1,13 +1,25 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
* @package CodeIgniter
- * @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
- * @license http://codeigniter.com/user_guide/license.html
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
@@ -21,18 +33,18 @@
* @package CodeIgniter
* @subpackage Libraries
* @category Libraries
- * @author ExpressionEngine Dev Team
+ * @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/libraries/ftp.html
*/
class CI_FTP {
- var $hostname = '';
- var $username = '';
- var $password = '';
- var $port = 21;
- var $passive = TRUE;
- var $debug = FALSE;
- var $conn_id = FALSE;
+ public $hostname = '';
+ public $username = '';
+ public $password = '';
+ public $port = 21;
+ public $passive = TRUE;
+ public $debug = FALSE;
+ public $conn_id = FALSE;
/**
@@ -59,7 +71,7 @@ class CI_FTP {
* @param array
* @return void
*/
- function initialize($config = array())
+ public function initialize($config = array())
{
foreach ($config as $key => $val)
{
@@ -82,7 +94,7 @@ class CI_FTP {
* @param array the connection values
* @return bool
*/
- function connect($config = array())
+ public function connect($config = array())
{
if (count($config) > 0)
{
@@ -124,7 +136,7 @@ class CI_FTP {
* @access private
* @return bool
*/
- function _login()
+ private function _login()
{
return @ftp_login($this->conn_id, $this->username, $this->password);
}
@@ -137,7 +149,7 @@ class CI_FTP {
* @access private
* @return bool
*/
- function _is_conn()
+ private function _is_conn()
{
if ( ! is_resource($this->conn_id))
{
@@ -167,7 +179,7 @@ class CI_FTP {
* @param bool
* @return bool
*/
- function changedir($path = '', $supress_debug = FALSE)
+ public function changedir($path = '', $supress_debug = FALSE)
{
if ($path == '' OR ! $this->_is_conn())
{
@@ -197,7 +209,7 @@ class CI_FTP {
* @param string
* @return bool
*/
- function mkdir($path = '', $permissions = NULL)
+ public function mkdir($path = '', $permissions = NULL)
{
if ($path == '' OR ! $this->_is_conn())
{
@@ -235,7 +247,7 @@ class CI_FTP {
* @param string
* @return bool
*/
- function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL)
+ public function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL)
{
if ( ! $this->_is_conn())
{
@@ -249,14 +261,14 @@ class CI_FTP {
}
// Set the mode if not specified
- if ($mode == 'auto')
+ if ($mode === 'auto')
{
// Get the file extension so we can set the upload type
$ext = $this->_getext($locpath);
$mode = $this->_settype($ext);
}
- $mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY;
+ $mode = ($mode === 'ascii') ? FTP_ASCII : FTP_BINARY;
$result = @ftp_put($this->conn_id, $rempath, $locpath, $mode);
@@ -289,7 +301,7 @@ class CI_FTP {
* @param string
* @return bool
*/
- function download($rempath, $locpath, $mode = 'auto')
+ public function download($rempath, $locpath, $mode = 'auto')
{
if ( ! $this->_is_conn())
{
@@ -297,14 +309,14 @@ class CI_FTP {
}
// Set the mode if not specified
- if ($mode == 'auto')
+ if ($mode === 'auto')
{
// Get the file extension so we can set the upload type
$ext = $this->_getext($rempath);
$mode = $this->_settype($ext);
}
- $mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY;
+ $mode = ($mode === 'ascii') ? FTP_ASCII : FTP_BINARY;
$result = @ftp_get($this->conn_id, $locpath, $rempath, $mode);
@@ -331,7 +343,7 @@ class CI_FTP {
* @param bool
* @return bool
*/
- function rename($old_file, $new_file, $move = FALSE)
+ public function rename($old_file, $new_file, $move = FALSE)
{
if ( ! $this->_is_conn())
{
@@ -344,9 +356,7 @@ class CI_FTP {
{
if ($this->debug == TRUE)
{
- $msg = ($move == FALSE) ? 'ftp_unable_to_rename' : 'ftp_unable_to_move';
-
- $this->_error($msg);
+ $this->_error('ftp_unable_to_' . ($move == FALSE ? 'rename' : 'move'));
}
return FALSE;
}
@@ -364,7 +374,7 @@ class CI_FTP {
* @param string
* @return bool
*/
- function move($old_file, $new_file)
+ public function move($old_file, $new_file)
{
return $this->rename($old_file, $new_file, TRUE);
}
@@ -378,7 +388,7 @@ class CI_FTP {
* @param string
* @return bool
*/
- function delete_file($filepath)
+ public function delete_file($filepath)
{
if ( ! $this->_is_conn())
{
@@ -409,7 +419,7 @@ class CI_FTP {
* @param string
* @return bool
*/
- function delete_dir($filepath)
+ public function delete_dir($filepath)
{
if ( ! $this->_is_conn())
{
@@ -458,23 +468,13 @@ class CI_FTP {
* @param string the permissions
* @return bool
*/
- function chmod($path, $perm)
+ public function chmod($path, $perm)
{
if ( ! $this->_is_conn())
{
return FALSE;
}
- // Permissions can only be set when running PHP 5
- if ( ! function_exists('ftp_chmod'))
- {
- if ($this->debug == TRUE)
- {
- $this->_error('ftp_unable_to_chmod');
- }
- return FALSE;
- }
-
$result = @ftp_chmod($this->conn_id, $perm, $path);
if ($result === FALSE)
@@ -497,7 +497,7 @@ class CI_FTP {
* @access public
* @return array
*/
- function list_files($path = '.')
+ public function list_files($path = '.')
{
if ( ! $this->_is_conn())
{
@@ -521,7 +521,7 @@ class CI_FTP {
* @param string path to destination - include the base folder with trailing slash
* @return bool
*/
- function mirror($locpath, $rempath)
+ public function mirror($locpath, $rempath)
{
if ( ! $this->_is_conn())
{
@@ -531,24 +531,20 @@ class CI_FTP {
// Open the local file path
if ($fp = @opendir($locpath))
{
- // Attempt to open the remote file path.
- if ( ! $this->changedir($rempath, TRUE))
+ // Attempt to open the remote file path and try to create it, if it doesn't exist
+ if ( ! $this->changedir($rempath, TRUE) AND ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath)))
{
- // If it doesn't exist we'll attempt to create the direcotory
- if ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath))
- {
- return FALSE;
- }
+ return FALSE;
}
// Recursively read the local directory
while (FALSE !== ($file = readdir($fp)))
{
- if (@is_dir($locpath.$file) && substr($file, 0, 1) != '.')
+ if (@is_dir($locpath.$file) && $file[0] !== '.')
{
$this->mirror($locpath.$file."/", $rempath.$file."/");
}
- elseif (substr($file, 0, 1) != ".")
+ elseif ($file[0] !== ".")
{
// Get the file extension so we can se the upload type
$ext = $this->_getext($file);
@@ -573,7 +569,7 @@ class CI_FTP {
* @param string
* @return string
*/
- function _getext($filename)
+ private function _getext($filename)
{
if (FALSE === strpos($filename, '.'))
{
@@ -594,7 +590,7 @@ class CI_FTP {
* @param string
* @return string
*/
- function _settype($ext)
+ private function _settype($ext)
{
$text_types = array(
'txt',
@@ -622,18 +618,16 @@ class CI_FTP {
* Close the connection
*
* @access public
- * @param string path to source
- * @param string path to destination
* @return bool
*/
- function close()
+ public function close()
{
if ( ! $this->_is_conn())
{
return FALSE;
}
- @ftp_close($this->conn_id);
+ return @ftp_close($this->conn_id);
}
// ------------------------------------------------------------------------
@@ -643,9 +637,9 @@ class CI_FTP {
*
* @access private
* @param string
- * @return bool
+ * @return void
*/
- function _error($line)
+ private function _error($line)
{
$CI =& get_instance();
$CI->lang->load('ftp');
@@ -657,4 +651,4 @@ class CI_FTP {
// END FTP Class
/* End of file Ftp.php */
-/* Location: ./system/libraries/Ftp.php */ \ No newline at end of file
+/* Location: ./system/libraries/Ftp.php */