blob: b9954c7f28569fcaf2a85b91829b5975f519c084 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * FTP Class
31 *
32 * @package CodeIgniter
33 * @subpackage Libraries
34 * @category Libraries
Derek Jonesf4a4bd82011-10-20 12:18:42 -050035 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @link http://codeigniter.com/user_guide/libraries/ftp.html
37 */
38class CI_FTP {
39
Andrey Andreev0a75d6e2011-12-22 19:45:33 +020040 public $hostname = '';
41 public $username = '';
42 public $password = '';
43 public $port = 21;
Andrey Andreevc4d979c2012-03-26 14:53:00 +030044 public $passive = TRUE;
Andrey Andreev0a75d6e2011-12-22 19:45:33 +020045 public $debug = FALSE;
Andrey Andreevc4d979c2012-03-26 14:53:00 +030046 public $conn_id = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +000047
Andrey Andreev5fd3ae82012-10-24 14:55:35 +030048 /**
49 * Constructor
50 *
51 * @param array $config = array()
52 * @return void
53 */
Greg Akera9263282010-11-10 15:26:43 -060054 public function __construct($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000055 {
56 if (count($config) > 0)
57 {
58 $this->initialize($config);
59 }
60
Andrey Andreevc4d979c2012-03-26 14:53:00 +030061 log_message('debug', 'FTP Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +000062 }
63
64 // --------------------------------------------------------------------
65
66 /**
67 * Initialize preferences
68 *
Derek Allard2067d1a2008-11-13 22:59:24 +000069 * @param array
70 * @return void
71 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +020072 public function initialize($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000073 {
74 foreach ($config as $key => $val)
75 {
76 if (isset($this->$key))
77 {
78 $this->$key = $val;
79 }
80 }
81
82 // Prep the hostname
83 $this->hostname = preg_replace('|.+?://|', '', $this->hostname);
84 }
85
86 // --------------------------------------------------------------------
87
88 /**
89 * FTP Connect
90 *
Derek Allard2067d1a2008-11-13 22:59:24 +000091 * @param array the connection values
92 * @return bool
93 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +020094 public function connect($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000095 {
96 if (count($config) > 0)
97 {
98 $this->initialize($config);
99 }
100
101 if (FALSE === ($this->conn_id = @ftp_connect($this->hostname, $this->port)))
102 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100103 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000104 {
105 $this->_error('ftp_unable_to_connect');
106 }
107 return FALSE;
108 }
109
110 if ( ! $this->_login())
111 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100112 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000113 {
114 $this->_error('ftp_unable_to_login');
115 }
116 return FALSE;
117 }
118
119 // Set passive mode if needed
Alex Bilbied261b1e2012-06-02 11:12:16 +0100120 if ($this->passive === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 {
122 ftp_pasv($this->conn_id, TRUE);
123 }
124
125 return TRUE;
126 }
127
128 // --------------------------------------------------------------------
129
130 /**
131 * FTP Login
132 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 * @return bool
134 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300135 protected function _login()
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 {
137 return @ftp_login($this->conn_id, $this->username, $this->password);
138 }
139
140 // --------------------------------------------------------------------
141
142 /**
143 * Validates the connection ID
144 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 * @return bool
146 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300147 protected function _is_conn()
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 {
149 if ( ! is_resource($this->conn_id))
150 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100151 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 {
153 $this->_error('ftp_no_connection');
154 }
155 return FALSE;
156 }
157 return TRUE;
158 }
159
160 // --------------------------------------------------------------------
161
Derek Allard2067d1a2008-11-13 22:59:24 +0000162 /**
Derek Allarda14ab122009-07-13 12:01:01 +0000163 * Change directory
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 *
165 * The second parameter lets us momentarily turn off debugging so that
Derek Allarda14ab122009-07-13 12:01:01 +0000166 * this function can be used to test for the existence of a folder
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300167 * without throwing an error. There's no FTP equivalent to is_dir()
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 * so we do it by trying to change to a particular directory.
Derek Allarda14ab122009-07-13 12:01:01 +0000169 * Internally, this parameter is only used by the "mirror" function below.
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000171 * @param string
172 * @param bool
173 * @return bool
174 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200175 public function changedir($path = '', $supress_debug = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000176 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100177 if ($path === '' OR ! $this->_is_conn())
Derek Allard2067d1a2008-11-13 22:59:24 +0000178 {
179 return FALSE;
180 }
181
182 $result = @ftp_chdir($this->conn_id, $path);
183
184 if ($result === FALSE)
185 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100186 if ($this->debug === TRUE && $supress_debug === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000187 {
188 $this->_error('ftp_unable_to_changedir');
189 }
190 return FALSE;
191 }
192
193 return TRUE;
194 }
195
196 // --------------------------------------------------------------------
197
198 /**
199 * Create a directory
200 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000201 * @param string
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300202 * @param int
Derek Allard2067d1a2008-11-13 22:59:24 +0000203 * @return bool
204 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200205 public function mkdir($path = '', $permissions = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000206 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100207 if ($path === '' OR ! $this->_is_conn())
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 {
209 return FALSE;
210 }
211
212 $result = @ftp_mkdir($this->conn_id, $path);
213
214 if ($result === FALSE)
215 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100216 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000217 {
218 $this->_error('ftp_unable_to_makdir');
219 }
220 return FALSE;
221 }
222
223 // Set file permissions if needed
224 if ( ! is_null($permissions))
225 {
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300226 $this->chmod($path, (int) $permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000227 }
228
229 return TRUE;
230 }
231
232 // --------------------------------------------------------------------
233
234 /**
235 * Upload a file to the server
236 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000237 * @param string
238 * @param string
239 * @param string
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300240 * @param int
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 * @return bool
242 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200243 public function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000244 {
245 if ( ! $this->_is_conn())
246 {
247 return FALSE;
248 }
249
250 if ( ! file_exists($locpath))
251 {
252 $this->_error('ftp_no_source_file');
253 return FALSE;
254 }
255
256 // Set the mode if not specified
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200257 if ($mode === 'auto')
Derek Allard2067d1a2008-11-13 22:59:24 +0000258 {
259 // Get the file extension so we can set the upload type
260 $ext = $this->_getext($locpath);
261 $mode = $this->_settype($ext);
262 }
263
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200264 $mode = ($mode === 'ascii') ? FTP_ASCII : FTP_BINARY;
Derek Allard2067d1a2008-11-13 22:59:24 +0000265
266 $result = @ftp_put($this->conn_id, $rempath, $locpath, $mode);
267
268 if ($result === FALSE)
269 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100270 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000271 {
272 $this->_error('ftp_unable_to_upload');
273 }
274 return FALSE;
275 }
276
277 // Set file permissions if needed
278 if ( ! is_null($permissions))
279 {
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300280 $this->chmod($rempath, (int) $permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000281 }
282
283 return TRUE;
284 }
285
286 // --------------------------------------------------------------------
287
288 /**
Phil Sturgeon28b29372010-03-12 00:43:28 +0000289 * Download a file from a remote server to the local server
290 *
Phil Sturgeon28b29372010-03-12 00:43:28 +0000291 * @param string
292 * @param string
293 * @param string
294 * @return bool
295 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200296 public function download($rempath, $locpath, $mode = 'auto')
Phil Sturgeon28b29372010-03-12 00:43:28 +0000297 {
298 if ( ! $this->_is_conn())
299 {
300 return FALSE;
301 }
Barry Mienydd671972010-10-04 16:33:58 +0200302
Phil Sturgeon28b29372010-03-12 00:43:28 +0000303 // Set the mode if not specified
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200304 if ($mode === 'auto')
Phil Sturgeon28b29372010-03-12 00:43:28 +0000305 {
306 // Get the file extension so we can set the upload type
307 $ext = $this->_getext($rempath);
308 $mode = $this->_settype($ext);
309 }
Barry Mienydd671972010-10-04 16:33:58 +0200310
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200311 $mode = ($mode === 'ascii') ? FTP_ASCII : FTP_BINARY;
Barry Mienydd671972010-10-04 16:33:58 +0200312
Phil Sturgeon28b29372010-03-12 00:43:28 +0000313 $result = @ftp_get($this->conn_id, $locpath, $rempath, $mode);
314
315 if ($result === FALSE)
316 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100317 if ($this->debug === TRUE)
Phil Sturgeon28b29372010-03-12 00:43:28 +0000318 {
319 $this->_error('ftp_unable_to_download');
320 }
Barry Mienydd671972010-10-04 16:33:58 +0200321 return FALSE;
Phil Sturgeon28b29372010-03-12 00:43:28 +0000322 }
Barry Mienydd671972010-10-04 16:33:58 +0200323
Phil Sturgeon28b29372010-03-12 00:43:28 +0000324 return TRUE;
Barry Mienydd671972010-10-04 16:33:58 +0200325 }
Phil Sturgeon28b29372010-03-12 00:43:28 +0000326
327 // --------------------------------------------------------------------
328
329 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000330 * Rename (or move) a file
331 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 * @param string
333 * @param string
334 * @param bool
335 * @return bool
336 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200337 public function rename($old_file, $new_file, $move = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000338 {
339 if ( ! $this->_is_conn())
340 {
341 return FALSE;
342 }
343
344 $result = @ftp_rename($this->conn_id, $old_file, $new_file);
345
346 if ($result === FALSE)
347 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100348 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000349 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100350 $this->_error('ftp_unable_to_' . ($move === FALSE ? 'rename' : 'move'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000351 }
352 return FALSE;
353 }
354
355 return TRUE;
356 }
357
358 // --------------------------------------------------------------------
359
360 /**
361 * Move a file
362 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000363 * @param string
364 * @param string
365 * @return bool
366 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200367 public function move($old_file, $new_file)
Derek Allard2067d1a2008-11-13 22:59:24 +0000368 {
369 return $this->rename($old_file, $new_file, TRUE);
370 }
371
372 // --------------------------------------------------------------------
373
374 /**
375 * Rename (or move) a file
376 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 * @param string
378 * @return bool
379 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200380 public function delete_file($filepath)
Derek Allard2067d1a2008-11-13 22:59:24 +0000381 {
382 if ( ! $this->_is_conn())
383 {
384 return FALSE;
385 }
386
387 $result = @ftp_delete($this->conn_id, $filepath);
388
389 if ($result === FALSE)
390 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100391 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000392 {
393 $this->_error('ftp_unable_to_delete');
394 }
395 return FALSE;
396 }
397
398 return TRUE;
399 }
400
401 // --------------------------------------------------------------------
402
403 /**
404 * Delete a folder and recursively delete everything (including sub-folders)
405 * containted within it.
406 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000407 * @param string
408 * @return bool
409 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200410 public function delete_dir($filepath)
Derek Allard2067d1a2008-11-13 22:59:24 +0000411 {
412 if ( ! $this->_is_conn())
413 {
414 return FALSE;
415 }
416
417 // Add a trailing slash to the file path if needed
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300418 $filepath = preg_replace('/(.+?)\/*$/', '\\1/', $filepath);
Derek Allard2067d1a2008-11-13 22:59:24 +0000419
420 $list = $this->list_files($filepath);
421
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300422 if ($list !== FALSE && count($list) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000423 {
424 foreach ($list as $item)
425 {
426 // If we can't delete the item it's probaly a folder so
427 // we'll recursively call delete_dir()
428 if ( ! @ftp_delete($this->conn_id, $item))
429 {
430 $this->delete_dir($item);
431 }
432 }
433 }
434
435 $result = @ftp_rmdir($this->conn_id, $filepath);
436
437 if ($result === FALSE)
438 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100439 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 {
441 $this->_error('ftp_unable_to_delete');
442 }
443 return FALSE;
444 }
445
446 return TRUE;
447 }
448
449 // --------------------------------------------------------------------
450
451 /**
452 * Set file permissions
453 *
Barry Mienydd671972010-10-04 16:33:58 +0200454 * @param string the file path
vlakoff625c43a2012-06-27 03:28:55 +0200455 * @param int the permissions
Derek Allard2067d1a2008-11-13 22:59:24 +0000456 * @return bool
457 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200458 public function chmod($path, $perm)
Derek Allard2067d1a2008-11-13 22:59:24 +0000459 {
460 if ( ! $this->_is_conn())
461 {
462 return FALSE;
463 }
464
Derek Allard2067d1a2008-11-13 22:59:24 +0000465 $result = @ftp_chmod($this->conn_id, $perm, $path);
466
467 if ($result === FALSE)
468 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100469 if ($this->debug === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000470 {
471 $this->_error('ftp_unable_to_chmod');
472 }
473 return FALSE;
474 }
475
476 return TRUE;
477 }
478
479 // --------------------------------------------------------------------
480
481 /**
482 * FTP List files in the specified directory
483 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300484 * @param string $path = '.'
Derek Allard2067d1a2008-11-13 22:59:24 +0000485 * @return array
486 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200487 public function list_files($path = '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000488 {
489 if ( ! $this->_is_conn())
490 {
491 return FALSE;
492 }
493
494 return ftp_nlist($this->conn_id, $path);
495 }
496
497 // ------------------------------------------------------------------------
498
499 /**
500 * Read a directory and recreate it remotely
501 *
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300502 * This function recursively reads a folder and everything it contains
503 * (including sub-folders) and creates a mirror via FTP based on it.
504 * Whatever the directory structure of the original file path will be
505 * recreated on the server.
Derek Allard2067d1a2008-11-13 22:59:24 +0000506 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000507 * @param string path to source with trailing slash
508 * @param string path to destination - include the base folder with trailing slash
509 * @return bool
510 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200511 public function mirror($locpath, $rempath)
Derek Allard2067d1a2008-11-13 22:59:24 +0000512 {
513 if ( ! $this->_is_conn())
514 {
515 return FALSE;
516 }
517
518 // Open the local file path
519 if ($fp = @opendir($locpath))
520 {
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200521 // Attempt to open the remote file path and try to create it, if it doesn't exist
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300522 if ( ! $this->changedir($rempath, TRUE) && ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000523 {
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200524 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000525 }
526
527 // Recursively read the local directory
528 while (FALSE !== ($file = readdir($fp)))
529 {
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200530 if (@is_dir($locpath.$file) && $file[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000531 {
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300532 $this->mirror($locpath.$file.'/', $rempath.$file.'/');
Derek Allard2067d1a2008-11-13 22:59:24 +0000533 }
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300534 elseif ($file[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000535 {
536 // Get the file extension so we can se the upload type
537 $ext = $this->_getext($file);
538 $mode = $this->_settype($ext);
539
540 $this->upload($locpath.$file, $rempath.$file, $mode);
541 }
542 }
543 return TRUE;
544 }
545
546 return FALSE;
547 }
548
Derek Allard2067d1a2008-11-13 22:59:24 +0000549 // --------------------------------------------------------------------
550
551 /**
552 * Extract the file extension
553 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000554 * @param string
555 * @return string
556 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300557 protected function _getext($filename)
Derek Allard2067d1a2008-11-13 22:59:24 +0000558 {
559 if (FALSE === strpos($filename, '.'))
560 {
561 return 'txt';
562 }
563
564 $x = explode('.', $filename);
565 return end($x);
566 }
567
Derek Allard2067d1a2008-11-13 22:59:24 +0000568 // --------------------------------------------------------------------
569
570 /**
571 * Set the upload type
572 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000573 * @param string
574 * @return string
575 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300576 protected function _settype($ext)
Derek Allard2067d1a2008-11-13 22:59:24 +0000577 {
578 $text_types = array(
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300579 'txt',
580 'text',
581 'php',
582 'phps',
583 'php4',
584 'js',
585 'css',
586 'htm',
587 'html',
588 'phtml',
589 'shtml',
590 'log',
591 'xml'
592 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000593
594
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300595 return in_array($ext, $text_types) ? 'ascii' : 'binary';
Derek Allard2067d1a2008-11-13 22:59:24 +0000596 }
597
598 // ------------------------------------------------------------------------
599
600 /**
601 * Close the connection
602 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000603 * @return bool
604 */
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200605 public function close()
Derek Allard2067d1a2008-11-13 22:59:24 +0000606 {
607 if ( ! $this->_is_conn())
608 {
609 return FALSE;
610 }
611
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200612 return @ftp_close($this->conn_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000613 }
614
615 // ------------------------------------------------------------------------
616
617 /**
618 * Display error message
619 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000620 * @param string
Andrey Andreev0a75d6e2011-12-22 19:45:33 +0200621 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000622 */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300623 protected function _error($line)
Derek Allard2067d1a2008-11-13 22:59:24 +0000624 {
625 $CI =& get_instance();
626 $CI->lang->load('ftp');
627 show_error($CI->lang->line($line));
628 }
629
Derek Allard2067d1a2008-11-13 22:59:24 +0000630}
Derek Allard2067d1a2008-11-13 22:59:24 +0000631
632/* End of file Ftp.php */
Andrey Andreevc4d979c2012-03-26 14:53:00 +0300633/* Location: ./system/libraries/Ftp.php */