blob: ae85fdf37c0f7a679905b9f7d0a86d497982aeee [file] [log] [blame]
Andrey Andreev0a75d6e2011-12-22 19:45:33 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev0a75d6e2011-12-22 19:45:33 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev0a75d6e2011-12-22 19:45:33 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * FTP Class
30 *
31 * @package CodeIgniter
32 * @subpackage Libraries
33 * @category Libraries
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000035 * @link http://codeigniter.com/user_guide/libraries/ftp.html
36 */
37class CI_FTP {
38
Andrey Andreev0a75d6e2011-12-22 19:45:33 +020039 public $hostname = '';
40 public $username = '';
41 public $password = '';
42 public $port = 21;
Andrey Andreevc4d979c2012-03-26 14:53:00 +030043 public $passive = TRUE;
Andrey Andreev0a75d6e2011-12-22 19:45:33 +020044 public $debug = FALSE;
Andrey Andreevc4d979c2012-03-26 14:53:00 +030045 public $conn_id = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +000046
Andrey Andreev5fd3ae82012-10-24 14:55:35 +030047 /**
48 * Constructor
49 *
50 * @param array $config = array()
51 * @return void
52 */
Greg Akera9263282010-11-10 15:26:43 -060053 public function __construct($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000054 {
55 if (count($config) > 0)
56 {
57 $this->initialize($config);
58 }
59
Andrey Andreevc4d979c2012-03-26 14:53:00 +030060 log_message('debug', 'FTP Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +000061 }
62
63 // --------------------------------------------------------------------
64
65 /**
66 * Initialize preferences
67 *
Derek Allard2067d1a2008-11-13 22:59:24 +000068 * @param array
69 * @return void
70 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +020071 public function initialize($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000072 {
73 foreach ($config as $key => $val)
74 {
75 if (isset($this->$key))
76 {
77 $this->$key = $val;
78 }
79 }
80
81 // Prep the hostname
82 $this->hostname = preg_replace('|.+?://|', '', $this->hostname);
83 }
84
85 // --------------------------------------------------------------------
86
87 /**
88 * FTP Connect
89 *
Derek Allard2067d1a2008-11-13 22:59:24 +000090 * @param array the connection values
91 * @return bool
92 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +020093 public function connect($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000094 {
95 if (count($config) > 0)
96 {
97 $this->initialize($config);
98 }
99
100 if (FALSE === ($this->conn_id = @ftp_connect($this->hostname, $this->port)))
101 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100102 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000103 {
104 $this->_error('ftp_unable_to_connect');
105 }
106 return FALSE;
107 }
108
109 if ( ! $this->_login())
110 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100111 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000112 {
113 $this->_error('ftp_unable_to_login');
114 }
115 return FALSE;
116 }
117
118 // Set passive mode if needed
Alex Bilbied261b1e2012-06-02 11:12:16 +0100119 if ($this->passive === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 {
121 ftp_pasv($this->conn_id, TRUE);
122 }
123
124 return TRUE;
125 }
126
127 // --------------------------------------------------------------------
128
129 /**
130 * FTP Login
131 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 * @return bool
133 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300134 protected function _login()
Derek Allard2067d1a2008-11-13 22:59:24 +0000135 {
136 return @ftp_login($this->conn_id, $this->username, $this->password);
137 }
138
139 // --------------------------------------------------------------------
140
141 /**
142 * Validates the connection ID
143 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000144 * @return bool
145 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300146 protected function _is_conn()
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 {
148 if ( ! is_resource($this->conn_id))
149 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100150 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000151 {
152 $this->_error('ftp_no_connection');
153 }
154 return FALSE;
155 }
156 return TRUE;
157 }
158
159 // --------------------------------------------------------------------
160
Derek Allard2067d1a2008-11-13 22:59:24 +0000161 /**
Derek Allarda14ab122009-07-13 12:01:01 +0000162 * Change directory
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 *
164 * The second parameter lets us momentarily turn off debugging so that
Derek Allarda14ab122009-07-13 12:01:01 +0000165 * this function can be used to test for the existence of a folder
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300166 * without throwing an error. There's no FTP equivalent to is_dir()
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 * so we do it by trying to change to a particular directory.
Derek Allarda14ab122009-07-13 12:01:01 +0000168 * Internally, this parameter is only used by the "mirror" function below.
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 * @param string
171 * @param bool
172 * @return bool
173 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200174 public function changedir($path = '', $supress_debug = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000175 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100176 if ($path === '' OR ! $this->_is_conn())
Derek Allard2067d1a2008-11-13 22:59:24 +0000177 {
178 return FALSE;
179 }
180
181 $result = @ftp_chdir($this->conn_id, $path);
182
183 if ($result === FALSE)
184 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100185 if ($this->debug === TRUE && $supress_debug === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000186 {
187 $this->_error('ftp_unable_to_changedir');
188 }
189 return FALSE;
190 }
191
192 return TRUE;
193 }
194
195 // --------------------------------------------------------------------
196
197 /**
198 * Create a directory
199 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000200 * @param string
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300201 * @param int
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 * @return bool
203 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200204 public function mkdir($path = '', $permissions = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000205 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100206 if ($path === '' OR ! $this->_is_conn())
Derek Allard2067d1a2008-11-13 22:59:24 +0000207 {
208 return FALSE;
209 }
210
211 $result = @ftp_mkdir($this->conn_id, $path);
212
213 if ($result === FALSE)
214 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100215 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000216 {
217 $this->_error('ftp_unable_to_makdir');
218 }
219 return FALSE;
220 }
221
222 // Set file permissions if needed
223 if ( ! is_null($permissions))
224 {
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300225 $this->chmod($path, (int) $permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 }
227
228 return TRUE;
229 }
230
231 // --------------------------------------------------------------------
232
233 /**
234 * Upload a file to the server
235 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000236 * @param string
237 * @param string
238 * @param string
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300239 * @param int
Derek Allard2067d1a2008-11-13 22:59:24 +0000240 * @return bool
241 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200242 public function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000243 {
244 if ( ! $this->_is_conn())
245 {
246 return FALSE;
247 }
248
249 if ( ! file_exists($locpath))
250 {
251 $this->_error('ftp_no_source_file');
252 return FALSE;
253 }
254
255 // Set the mode if not specified
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200256 if ($mode === 'auto')
Derek Allard2067d1a2008-11-13 22:59:24 +0000257 {
258 // Get the file extension so we can set the upload type
259 $ext = $this->_getext($locpath);
260 $mode = $this->_settype($ext);
261 }
262
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200263 $mode = ($mode === 'ascii') ? FTP_ASCII : FTP_BINARY;
Derek Allard2067d1a2008-11-13 22:59:24 +0000264
265 $result = @ftp_put($this->conn_id, $rempath, $locpath, $mode);
266
267 if ($result === FALSE)
268 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100269 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 {
271 $this->_error('ftp_unable_to_upload');
272 }
273 return FALSE;
274 }
275
276 // Set file permissions if needed
277 if ( ! is_null($permissions))
278 {
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300279 $this->chmod($rempath, (int) $permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 }
281
282 return TRUE;
283 }
284
285 // --------------------------------------------------------------------
286
287 /**
Phil Sturgeon28b29372010-03-12 00:43:28 +0000288 * Download a file from a remote server to the local server
289 *
Phil Sturgeon28b29372010-03-12 00:43:28 +0000290 * @param string
291 * @param string
292 * @param string
293 * @return bool
294 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200295 public function download($rempath, $locpath, $mode = 'auto')
Phil Sturgeon28b29372010-03-12 00:43:28 +0000296 {
297 if ( ! $this->_is_conn())
298 {
299 return FALSE;
300 }
Barry Mienydd671972010-10-04 16:33:58 +0200301
Phil Sturgeon28b29372010-03-12 00:43:28 +0000302 // Set the mode if not specified
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200303 if ($mode === 'auto')
Phil Sturgeon28b29372010-03-12 00:43:28 +0000304 {
305 // Get the file extension so we can set the upload type
306 $ext = $this->_getext($rempath);
307 $mode = $this->_settype($ext);
308 }
Barry Mienydd671972010-10-04 16:33:58 +0200309
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200310 $mode = ($mode === 'ascii') ? FTP_ASCII : FTP_BINARY;
Barry Mienydd671972010-10-04 16:33:58 +0200311
Phil Sturgeon28b29372010-03-12 00:43:28 +0000312 $result = @ftp_get($this->conn_id, $locpath, $rempath, $mode);
313
314 if ($result === FALSE)
315 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100316 if ($this->debug === TRUE)
Phil Sturgeon28b29372010-03-12 00:43:28 +0000317 {
318 $this->_error('ftp_unable_to_download');
319 }
Barry Mienydd671972010-10-04 16:33:58 +0200320 return FALSE;
Phil Sturgeon28b29372010-03-12 00:43:28 +0000321 }
Barry Mienydd671972010-10-04 16:33:58 +0200322
Phil Sturgeon28b29372010-03-12 00:43:28 +0000323 return TRUE;
Barry Mienydd671972010-10-04 16:33:58 +0200324 }
Phil Sturgeon28b29372010-03-12 00:43:28 +0000325
326 // --------------------------------------------------------------------
327
328 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000329 * Rename (or move) a file
330 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000331 * @param string
332 * @param string
333 * @param bool
334 * @return bool
335 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200336 public function rename($old_file, $new_file, $move = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000337 {
338 if ( ! $this->_is_conn())
339 {
340 return FALSE;
341 }
342
343 $result = @ftp_rename($this->conn_id, $old_file, $new_file);
344
345 if ($result === FALSE)
346 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100347 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000348 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100349 $this->_error('ftp_unable_to_' . ($move === FALSE ? 'rename' : 'move'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 }
351 return FALSE;
352 }
353
354 return TRUE;
355 }
356
357 // --------------------------------------------------------------------
358
359 /**
360 * Move a file
361 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000362 * @param string
363 * @param string
364 * @return bool
365 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200366 public function move($old_file, $new_file)
Derek Allard2067d1a2008-11-13 22:59:24 +0000367 {
368 return $this->rename($old_file, $new_file, TRUE);
369 }
370
371 // --------------------------------------------------------------------
372
373 /**
374 * Rename (or move) a file
375 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000376 * @param string
377 * @return bool
378 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200379 public function delete_file($filepath)
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 {
381 if ( ! $this->_is_conn())
382 {
383 return FALSE;
384 }
385
386 $result = @ftp_delete($this->conn_id, $filepath);
387
388 if ($result === FALSE)
389 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100390 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000391 {
392 $this->_error('ftp_unable_to_delete');
393 }
394 return FALSE;
395 }
396
397 return TRUE;
398 }
399
400 // --------------------------------------------------------------------
401
402 /**
403 * Delete a folder and recursively delete everything (including sub-folders)
404 * containted within it.
405 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000406 * @param string
407 * @return bool
408 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200409 public function delete_dir($filepath)
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 {
411 if ( ! $this->_is_conn())
412 {
413 return FALSE;
414 }
415
416 // Add a trailing slash to the file path if needed
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300417 $filepath = preg_replace('/(.+?)\/*$/', '\\1/', $filepath);
Derek Allard2067d1a2008-11-13 22:59:24 +0000418
419 $list = $this->list_files($filepath);
420
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300421 if ($list !== FALSE && count($list) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000422 {
423 foreach ($list as $item)
424 {
425 // If we can't delete the item it's probaly a folder so
426 // we'll recursively call delete_dir()
427 if ( ! @ftp_delete($this->conn_id, $item))
428 {
429 $this->delete_dir($item);
430 }
431 }
432 }
433
434 $result = @ftp_rmdir($this->conn_id, $filepath);
435
436 if ($result === FALSE)
437 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100438 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000439 {
440 $this->_error('ftp_unable_to_delete');
441 }
442 return FALSE;
443 }
444
445 return TRUE;
446 }
447
448 // --------------------------------------------------------------------
449
450 /**
451 * Set file permissions
452 *
Barry Mienydd671972010-10-04 16:33:58 +0200453 * @param string the file path
vlakoff625c43a2012-06-27 03:28:55 +0200454 * @param int the permissions
Derek Allard2067d1a2008-11-13 22:59:24 +0000455 * @return bool
456 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200457 public function chmod($path, $perm)
Derek Allard2067d1a2008-11-13 22:59:24 +0000458 {
459 if ( ! $this->_is_conn())
460 {
461 return FALSE;
462 }
463
Derek Allard2067d1a2008-11-13 22:59:24 +0000464 $result = @ftp_chmod($this->conn_id, $perm, $path);
465
466 if ($result === FALSE)
467 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100468 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000469 {
470 $this->_error('ftp_unable_to_chmod');
471 }
472 return FALSE;
473 }
474
475 return TRUE;
476 }
477
478 // --------------------------------------------------------------------
479
480 /**
481 * FTP List files in the specified directory
482 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300483 * @param string $path = '.'
Derek Allard2067d1a2008-11-13 22:59:24 +0000484 * @return array
485 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200486 public function list_files($path = '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000487 {
488 if ( ! $this->_is_conn())
489 {
490 return FALSE;
491 }
492
493 return ftp_nlist($this->conn_id, $path);
494 }
495
496 // ------------------------------------------------------------------------
497
498 /**
499 * Read a directory and recreate it remotely
500 *
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300501 * This function recursively reads a folder and everything it contains
502 * (including sub-folders) and creates a mirror via FTP based on it.
503 * Whatever the directory structure of the original file path will be
504 * recreated on the server.
Derek Allard2067d1a2008-11-13 22:59:24 +0000505 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000506 * @param string path to source with trailing slash
507 * @param string path to destination - include the base folder with trailing slash
508 * @return bool
509 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200510 public function mirror($locpath, $rempath)
Derek Allard2067d1a2008-11-13 22:59:24 +0000511 {
512 if ( ! $this->_is_conn())
513 {
514 return FALSE;
515 }
516
517 // Open the local file path
518 if ($fp = @opendir($locpath))
519 {
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200520 // Attempt to open the remote file path and try to create it, if it doesn't exist
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300521 if ( ! $this->changedir($rempath, TRUE) && ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000522 {
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200523 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000524 }
525
526 // Recursively read the local directory
527 while (FALSE !== ($file = readdir($fp)))
528 {
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200529 if (@is_dir($locpath.$file) && $file[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000530 {
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300531 $this->mirror($locpath.$file.'/', $rempath.$file.'/');
Derek Allard2067d1a2008-11-13 22:59:24 +0000532 }
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300533 elseif ($file[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000534 {
535 // Get the file extension so we can se the upload type
536 $ext = $this->_getext($file);
537 $mode = $this->_settype($ext);
538
539 $this->upload($locpath.$file, $rempath.$file, $mode);
540 }
541 }
542 return TRUE;
543 }
544
545 return FALSE;
546 }
547
Derek Allard2067d1a2008-11-13 22:59:24 +0000548 // --------------------------------------------------------------------
549
550 /**
551 * Extract the file extension
552 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000553 * @param string
554 * @return string
555 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300556 protected function _getext($filename)
Derek Allard2067d1a2008-11-13 22:59:24 +0000557 {
558 if (FALSE === strpos($filename, '.'))
559 {
560 return 'txt';
561 }
562
563 $x = explode('.', $filename);
564 return end($x);
565 }
566
Derek Allard2067d1a2008-11-13 22:59:24 +0000567 // --------------------------------------------------------------------
568
569 /**
570 * Set the upload type
571 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000572 * @param string
573 * @return string
574 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300575 protected function _settype($ext)
Derek Allard2067d1a2008-11-13 22:59:24 +0000576 {
577 $text_types = array(
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300578 'txt',
579 'text',
580 'php',
581 'phps',
582 'php4',
583 'js',
584 'css',
585 'htm',
586 'html',
587 'phtml',
588 'shtml',
589 'log',
590 'xml'
591 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000592
593
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300594 return in_array($ext, $text_types) ? 'ascii' : 'binary';
Derek Allard2067d1a2008-11-13 22:59:24 +0000595 }
596
597 // ------------------------------------------------------------------------
598
599 /**
600 * Close the connection
601 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000602 * @return bool
603 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200604 public function close()
Derek Allard2067d1a2008-11-13 22:59:24 +0000605 {
606 if ( ! $this->_is_conn())
607 {
608 return FALSE;
609 }
610
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200611 return @ftp_close($this->conn_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000612 }
613
614 // ------------------------------------------------------------------------
615
616 /**
617 * Display error message
618 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000619 * @param string
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200620 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000621 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300622 protected function _error($line)
Derek Allard2067d1a2008-11-13 22:59:24 +0000623 {
624 $CI =& get_instance();
625 $CI->lang->load('ftp');
626 show_error($CI->lang->line($line));
627 }
628
Derek Allard2067d1a2008-11-13 22:59:24 +0000629}
Derek Allard2067d1a2008-11-13 22:59:24 +0000630
631/* End of file Ftp.php */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300632/* Location: ./system/libraries/Ftp.php */