blob: 76f5e151a8a3015fb3edad4e6447bdd0872f11a0 [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
Greg Akera9263282010-11-10 15:26:43 -060047 public function __construct($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000048 {
49 if (count($config) > 0)
50 {
51 $this->initialize($config);
52 }
53
Andrey Andreevc4d979c2012-03-26 14:53:00 +030054 log_message('debug', 'FTP Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +000055 }
56
57 // --------------------------------------------------------------------
58
59 /**
60 * Initialize preferences
61 *
Derek Allard2067d1a2008-11-13 22:59:24 +000062 * @param array
63 * @return void
64 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +020065 public function initialize($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000066 {
67 foreach ($config as $key => $val)
68 {
69 if (isset($this->$key))
70 {
71 $this->$key = $val;
72 }
73 }
74
75 // Prep the hostname
76 $this->hostname = preg_replace('|.+?://|', '', $this->hostname);
77 }
78
79 // --------------------------------------------------------------------
80
81 /**
82 * FTP Connect
83 *
Derek Allard2067d1a2008-11-13 22:59:24 +000084 * @param array the connection values
85 * @return bool
86 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +020087 public function connect($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000088 {
89 if (count($config) > 0)
90 {
91 $this->initialize($config);
92 }
93
94 if (FALSE === ($this->conn_id = @ftp_connect($this->hostname, $this->port)))
95 {
Alex Bilbied261b1e2012-06-02 11:12:16 +010096 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +000097 {
98 $this->_error('ftp_unable_to_connect');
99 }
100 return FALSE;
101 }
102
103 if ( ! $this->_login())
104 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100105 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000106 {
107 $this->_error('ftp_unable_to_login');
108 }
109 return FALSE;
110 }
111
112 // Set passive mode if needed
Alex Bilbied261b1e2012-06-02 11:12:16 +0100113 if ($this->passive === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000114 {
115 ftp_pasv($this->conn_id, TRUE);
116 }
117
118 return TRUE;
119 }
120
121 // --------------------------------------------------------------------
122
123 /**
124 * FTP Login
125 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000126 * @return bool
127 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300128 protected function _login()
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 {
130 return @ftp_login($this->conn_id, $this->username, $this->password);
131 }
132
133 // --------------------------------------------------------------------
134
135 /**
136 * Validates the connection ID
137 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000138 * @return bool
139 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300140 protected function _is_conn()
Derek Allard2067d1a2008-11-13 22:59:24 +0000141 {
142 if ( ! is_resource($this->conn_id))
143 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100144 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 {
146 $this->_error('ftp_no_connection');
147 }
148 return FALSE;
149 }
150 return TRUE;
151 }
152
153 // --------------------------------------------------------------------
154
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 /**
Derek Allarda14ab122009-07-13 12:01:01 +0000156 * Change directory
Derek Allard2067d1a2008-11-13 22:59:24 +0000157 *
158 * The second parameter lets us momentarily turn off debugging so that
Derek Allarda14ab122009-07-13 12:01:01 +0000159 * this function can be used to test for the existence of a folder
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300160 * without throwing an error. There's no FTP equivalent to is_dir()
Derek Allard2067d1a2008-11-13 22:59:24 +0000161 * so we do it by trying to change to a particular directory.
Derek Allarda14ab122009-07-13 12:01:01 +0000162 * Internally, this parameter is only used by the "mirror" function below.
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 * @param string
165 * @param bool
166 * @return bool
167 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200168 public function changedir($path = '', $supress_debug = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100170 if ($path === '' OR ! $this->_is_conn())
Derek Allard2067d1a2008-11-13 22:59:24 +0000171 {
172 return FALSE;
173 }
174
175 $result = @ftp_chdir($this->conn_id, $path);
176
177 if ($result === FALSE)
178 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100179 if ($this->debug === TRUE && $supress_debug === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000180 {
181 $this->_error('ftp_unable_to_changedir');
182 }
183 return FALSE;
184 }
185
186 return TRUE;
187 }
188
189 // --------------------------------------------------------------------
190
191 /**
192 * Create a directory
193 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000194 * @param string
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300195 * @param int
Derek Allard2067d1a2008-11-13 22:59:24 +0000196 * @return bool
197 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200198 public function mkdir($path = '', $permissions = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000199 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100200 if ($path === '' OR ! $this->_is_conn())
Derek Allard2067d1a2008-11-13 22:59:24 +0000201 {
202 return FALSE;
203 }
204
205 $result = @ftp_mkdir($this->conn_id, $path);
206
207 if ($result === FALSE)
208 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100209 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000210 {
211 $this->_error('ftp_unable_to_makdir');
212 }
213 return FALSE;
214 }
215
216 // Set file permissions if needed
217 if ( ! is_null($permissions))
218 {
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300219 $this->chmod($path, (int) $permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 }
221
222 return TRUE;
223 }
224
225 // --------------------------------------------------------------------
226
227 /**
228 * Upload a file to the server
229 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000230 * @param string
231 * @param string
232 * @param string
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300233 * @param int
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 * @return bool
235 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200236 public function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000237 {
238 if ( ! $this->_is_conn())
239 {
240 return FALSE;
241 }
242
243 if ( ! file_exists($locpath))
244 {
245 $this->_error('ftp_no_source_file');
246 return FALSE;
247 }
248
249 // Set the mode if not specified
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200250 if ($mode === 'auto')
Derek Allard2067d1a2008-11-13 22:59:24 +0000251 {
252 // Get the file extension so we can set the upload type
253 $ext = $this->_getext($locpath);
254 $mode = $this->_settype($ext);
255 }
256
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200257 $mode = ($mode === 'ascii') ? FTP_ASCII : FTP_BINARY;
Derek Allard2067d1a2008-11-13 22:59:24 +0000258
259 $result = @ftp_put($this->conn_id, $rempath, $locpath, $mode);
260
261 if ($result === FALSE)
262 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100263 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000264 {
265 $this->_error('ftp_unable_to_upload');
266 }
267 return FALSE;
268 }
269
270 // Set file permissions if needed
271 if ( ! is_null($permissions))
272 {
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300273 $this->chmod($rempath, (int) $permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000274 }
275
276 return TRUE;
277 }
278
279 // --------------------------------------------------------------------
280
281 /**
Phil Sturgeon28b29372010-03-12 00:43:28 +0000282 * Download a file from a remote server to the local server
283 *
Phil Sturgeon28b29372010-03-12 00:43:28 +0000284 * @param string
285 * @param string
286 * @param string
287 * @return bool
288 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200289 public function download($rempath, $locpath, $mode = 'auto')
Phil Sturgeon28b29372010-03-12 00:43:28 +0000290 {
291 if ( ! $this->_is_conn())
292 {
293 return FALSE;
294 }
Barry Mienydd671972010-10-04 16:33:58 +0200295
Phil Sturgeon28b29372010-03-12 00:43:28 +0000296 // Set the mode if not specified
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200297 if ($mode === 'auto')
Phil Sturgeon28b29372010-03-12 00:43:28 +0000298 {
299 // Get the file extension so we can set the upload type
300 $ext = $this->_getext($rempath);
301 $mode = $this->_settype($ext);
302 }
Barry Mienydd671972010-10-04 16:33:58 +0200303
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200304 $mode = ($mode === 'ascii') ? FTP_ASCII : FTP_BINARY;
Barry Mienydd671972010-10-04 16:33:58 +0200305
Phil Sturgeon28b29372010-03-12 00:43:28 +0000306 $result = @ftp_get($this->conn_id, $locpath, $rempath, $mode);
307
308 if ($result === FALSE)
309 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100310 if ($this->debug === TRUE)
Phil Sturgeon28b29372010-03-12 00:43:28 +0000311 {
312 $this->_error('ftp_unable_to_download');
313 }
Barry Mienydd671972010-10-04 16:33:58 +0200314 return FALSE;
Phil Sturgeon28b29372010-03-12 00:43:28 +0000315 }
Barry Mienydd671972010-10-04 16:33:58 +0200316
Phil Sturgeon28b29372010-03-12 00:43:28 +0000317 return TRUE;
Barry Mienydd671972010-10-04 16:33:58 +0200318 }
Phil Sturgeon28b29372010-03-12 00:43:28 +0000319
320 // --------------------------------------------------------------------
321
322 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000323 * Rename (or move) a file
324 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000325 * @param string
326 * @param string
327 * @param bool
328 * @return bool
329 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200330 public function rename($old_file, $new_file, $move = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000331 {
332 if ( ! $this->_is_conn())
333 {
334 return FALSE;
335 }
336
337 $result = @ftp_rename($this->conn_id, $old_file, $new_file);
338
339 if ($result === FALSE)
340 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100341 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000342 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100343 $this->_error('ftp_unable_to_' . ($move === FALSE ? 'rename' : 'move'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000344 }
345 return FALSE;
346 }
347
348 return TRUE;
349 }
350
351 // --------------------------------------------------------------------
352
353 /**
354 * Move a file
355 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000356 * @param string
357 * @param string
358 * @return bool
359 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200360 public function move($old_file, $new_file)
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 {
362 return $this->rename($old_file, $new_file, TRUE);
363 }
364
365 // --------------------------------------------------------------------
366
367 /**
368 * Rename (or move) a file
369 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000370 * @param string
371 * @return bool
372 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200373 public function delete_file($filepath)
Derek Allard2067d1a2008-11-13 22:59:24 +0000374 {
375 if ( ! $this->_is_conn())
376 {
377 return FALSE;
378 }
379
380 $result = @ftp_delete($this->conn_id, $filepath);
381
382 if ($result === FALSE)
383 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100384 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000385 {
386 $this->_error('ftp_unable_to_delete');
387 }
388 return FALSE;
389 }
390
391 return TRUE;
392 }
393
394 // --------------------------------------------------------------------
395
396 /**
397 * Delete a folder and recursively delete everything (including sub-folders)
398 * containted within it.
399 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000400 * @param string
401 * @return bool
402 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200403 public function delete_dir($filepath)
Derek Allard2067d1a2008-11-13 22:59:24 +0000404 {
405 if ( ! $this->_is_conn())
406 {
407 return FALSE;
408 }
409
410 // Add a trailing slash to the file path if needed
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300411 $filepath = preg_replace('/(.+?)\/*$/', '\\1/', $filepath);
Derek Allard2067d1a2008-11-13 22:59:24 +0000412
413 $list = $this->list_files($filepath);
414
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300415 if ($list !== FALSE && count($list) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000416 {
417 foreach ($list as $item)
418 {
419 // If we can't delete the item it's probaly a folder so
420 // we'll recursively call delete_dir()
421 if ( ! @ftp_delete($this->conn_id, $item))
422 {
423 $this->delete_dir($item);
424 }
425 }
426 }
427
428 $result = @ftp_rmdir($this->conn_id, $filepath);
429
430 if ($result === FALSE)
431 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100432 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000433 {
434 $this->_error('ftp_unable_to_delete');
435 }
436 return FALSE;
437 }
438
439 return TRUE;
440 }
441
442 // --------------------------------------------------------------------
443
444 /**
445 * Set file permissions
446 *
Barry Mienydd671972010-10-04 16:33:58 +0200447 * @param string the file path
vlakoff625c43a2012-06-27 03:28:55 +0200448 * @param int the permissions
Derek Allard2067d1a2008-11-13 22:59:24 +0000449 * @return bool
450 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200451 public function chmod($path, $perm)
Derek Allard2067d1a2008-11-13 22:59:24 +0000452 {
453 if ( ! $this->_is_conn())
454 {
455 return FALSE;
456 }
457
Derek Allard2067d1a2008-11-13 22:59:24 +0000458 $result = @ftp_chmod($this->conn_id, $perm, $path);
459
460 if ($result === FALSE)
461 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100462 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000463 {
464 $this->_error('ftp_unable_to_chmod');
465 }
466 return FALSE;
467 }
468
469 return TRUE;
470 }
471
472 // --------------------------------------------------------------------
473
474 /**
475 * FTP List files in the specified directory
476 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000477 * @return array
478 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200479 public function list_files($path = '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000480 {
481 if ( ! $this->_is_conn())
482 {
483 return FALSE;
484 }
485
486 return ftp_nlist($this->conn_id, $path);
487 }
488
489 // ------------------------------------------------------------------------
490
491 /**
492 * Read a directory and recreate it remotely
493 *
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300494 * This function recursively reads a folder and everything it contains
495 * (including sub-folders) and creates a mirror via FTP based on it.
496 * Whatever the directory structure of the original file path will be
497 * recreated on the server.
Derek Allard2067d1a2008-11-13 22:59:24 +0000498 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000499 * @param string path to source with trailing slash
500 * @param string path to destination - include the base folder with trailing slash
501 * @return bool
502 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200503 public function mirror($locpath, $rempath)
Derek Allard2067d1a2008-11-13 22:59:24 +0000504 {
505 if ( ! $this->_is_conn())
506 {
507 return FALSE;
508 }
509
510 // Open the local file path
511 if ($fp = @opendir($locpath))
512 {
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200513 // Attempt to open the remote file path and try to create it, if it doesn't exist
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300514 if ( ! $this->changedir($rempath, TRUE) && ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000515 {
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200516 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000517 }
518
519 // Recursively read the local directory
520 while (FALSE !== ($file = readdir($fp)))
521 {
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200522 if (@is_dir($locpath.$file) && $file[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000523 {
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300524 $this->mirror($locpath.$file.'/', $rempath.$file.'/');
Derek Allard2067d1a2008-11-13 22:59:24 +0000525 }
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300526 elseif ($file[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000527 {
528 // Get the file extension so we can se the upload type
529 $ext = $this->_getext($file);
530 $mode = $this->_settype($ext);
531
532 $this->upload($locpath.$file, $rempath.$file, $mode);
533 }
534 }
535 return TRUE;
536 }
537
538 return FALSE;
539 }
540
Derek Allard2067d1a2008-11-13 22:59:24 +0000541 // --------------------------------------------------------------------
542
543 /**
544 * Extract the file extension
545 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000546 * @param string
547 * @return string
548 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300549 protected function _getext($filename)
Derek Allard2067d1a2008-11-13 22:59:24 +0000550 {
551 if (FALSE === strpos($filename, '.'))
552 {
553 return 'txt';
554 }
555
556 $x = explode('.', $filename);
557 return end($x);
558 }
559
Derek Allard2067d1a2008-11-13 22:59:24 +0000560 // --------------------------------------------------------------------
561
562 /**
563 * Set the upload type
564 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000565 * @param string
566 * @return string
567 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300568 protected function _settype($ext)
Derek Allard2067d1a2008-11-13 22:59:24 +0000569 {
570 $text_types = array(
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300571 'txt',
572 'text',
573 'php',
574 'phps',
575 'php4',
576 'js',
577 'css',
578 'htm',
579 'html',
580 'phtml',
581 'shtml',
582 'log',
583 'xml'
584 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000585
586
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300587 return in_array($ext, $text_types) ? 'ascii' : 'binary';
Derek Allard2067d1a2008-11-13 22:59:24 +0000588 }
589
590 // ------------------------------------------------------------------------
591
592 /**
593 * Close the connection
594 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000595 * @return bool
596 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200597 public function close()
Derek Allard2067d1a2008-11-13 22:59:24 +0000598 {
599 if ( ! $this->_is_conn())
600 {
601 return FALSE;
602 }
603
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200604 return @ftp_close($this->conn_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000605 }
606
607 // ------------------------------------------------------------------------
608
609 /**
610 * Display error message
611 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000612 * @param string
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200613 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000614 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300615 protected function _error($line)
Derek Allard2067d1a2008-11-13 22:59:24 +0000616 {
617 $CI =& get_instance();
618 $CI->lang->load('ftp');
619 show_error($CI->lang->line($line));
620 }
621
Derek Allard2067d1a2008-11-13 22:59:24 +0000622}
Derek Allard2067d1a2008-11-13 22:59:24 +0000623
624/* End of file Ftp.php */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300625/* Location: ./system/libraries/Ftp.php */