From 28b293729d2c2917c434c6296eafecd19f397303 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 12 Mar 2010 00:43:28 +0000 Subject: Added FTP::download() and the accompanying lang line. This was first proposed in 2007, can we add it now pleeeeease? --- system/language/english/ftp_lang.php | 1 + system/libraries/Ftp.php | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) (limited to 'system') diff --git a/system/language/english/ftp_lang.php b/system/language/english/ftp_lang.php index 42403b971..392b2b272 100644 --- a/system/language/english/ftp_lang.php +++ b/system/language/english/ftp_lang.php @@ -7,6 +7,7 @@ $lang['ftp_unable_to_makdir'] = "Unable to create the directory you have specif $lang['ftp_unable_to_changedir'] = "Unable to change directories."; $lang['ftp_unable_to_chmod'] = "Unable to set file permissions. Please check your path. Note: This feature is only available in PHP 5 or higher."; $lang['ftp_unable_to_upload'] = "Unable to upload the specified file. Please check your path."; +$lang['ftp_unable_to_download'] = "Unable to download the specified file. Please check your path."; $lang['ftp_no_source_file'] = "Unable to locate the source file. Please check your path."; $lang['ftp_unable_to_rename'] = "Unable to rename the file."; $lang['ftp_unable_to_delete'] = "Unable to delete the file."; diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 16ad9ad43..07f4b1ff3 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -280,6 +280,48 @@ class CI_FTP { // -------------------------------------------------------------------- + /** + * Download a file from a remote server to the local server + * + * @access public + * @param string + * @param string + * @param string + * @return bool + */ + function download($rempath, $locpath, $mode = 'auto') + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + + // Set the mode if not specified + 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; + + $result = @ftp_get($this->conn_id, $locpath, $rempath, $mode); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_download'); + } + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Rename (or move) a file * -- cgit v1.2.3-24-g4f1b