1
- <?php if ( ! defined ('BASEPATH ' )) exit ('No direct script access allowed ' );
1
+ <?php if ( ! defined ('BASEPATH ' )) exit ('No direct script access allowed ' );
2
2
/**
3
3
* CodeIgniter
4
4
*
5
5
* An open source application development framework for PHP 5.1.6 or newer
6
6
*
7
7
* NOTICE OF LICENSE
8
- *
8
+ *
9
9
* Licensed under the Open Software License version 3.0
10
- *
10
+ *
11
11
* This source file is subject to the Open Software License (OSL 3.0) that is
12
12
* bundled with this package in the files license.txt / license.rst. It is
13
13
* also available through the world wide web at this URL:
38
38
*/
39
39
class CI_FTP {
40
40
41
- var $ hostname = '' ;
42
- var $ username = '' ;
43
- var $ password = '' ;
44
- var $ port = 21 ;
45
- var $ passive = TRUE ;
46
- var $ debug = FALSE ;
47
- var $ conn_id = FALSE ;
41
+ public $ hostname = '' ;
42
+ public $ username = '' ;
43
+ public $ password = '' ;
44
+ public $ port = 21 ;
45
+ public $ passive = TRUE ;
46
+ public $ debug = FALSE ;
47
+ public $ conn_id = FALSE ;
48
48
49
49
50
50
/**
@@ -71,7 +71,7 @@ public function __construct($config = array())
71
71
* @param array
72
72
* @return void
73
73
*/
74
- function initialize ($ config = array ())
74
+ public function initialize ($ config = array ())
75
75
{
76
76
foreach ($ config as $ key => $ val )
77
77
{
@@ -94,7 +94,7 @@ function initialize($config = array())
94
94
* @param array the connection values
95
95
* @return bool
96
96
*/
97
- function connect ($ config = array ())
97
+ public function connect ($ config = array ())
98
98
{
99
99
if (count ($ config ) > 0 )
100
100
{
@@ -136,7 +136,7 @@ function connect($config = array())
136
136
* @access private
137
137
* @return bool
138
138
*/
139
- function _login ()
139
+ private function _login ()
140
140
{
141
141
return @ftp_login ($ this ->conn_id , $ this ->username , $ this ->password );
142
142
}
@@ -149,7 +149,7 @@ function _login()
149
149
* @access private
150
150
* @return bool
151
151
*/
152
- function _is_conn ()
152
+ private function _is_conn ()
153
153
{
154
154
if ( ! is_resource ($ this ->conn_id ))
155
155
{
@@ -179,7 +179,7 @@ function _is_conn()
179
179
* @param bool
180
180
* @return bool
181
181
*/
182
- function changedir ($ path = '' , $ supress_debug = FALSE )
182
+ public function changedir ($ path = '' , $ supress_debug = FALSE )
183
183
{
184
184
if ($ path == '' OR ! $ this ->_is_conn ())
185
185
{
@@ -209,7 +209,7 @@ function changedir($path = '', $supress_debug = FALSE)
209
209
* @param string
210
210
* @return bool
211
211
*/
212
- function mkdir ($ path = '' , $ permissions = NULL )
212
+ public function mkdir ($ path = '' , $ permissions = NULL )
213
213
{
214
214
if ($ path == '' OR ! $ this ->_is_conn ())
215
215
{
@@ -247,7 +247,7 @@ function mkdir($path = '', $permissions = NULL)
247
247
* @param string
248
248
* @return bool
249
249
*/
250
- function upload ($ locpath , $ rempath , $ mode = 'auto ' , $ permissions = NULL )
250
+ public function upload ($ locpath , $ rempath , $ mode = 'auto ' , $ permissions = NULL )
251
251
{
252
252
if ( ! $ this ->_is_conn ())
253
253
{
@@ -261,14 +261,14 @@ function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL)
261
261
}
262
262
263
263
// Set the mode if not specified
264
- if ($ mode == 'auto ' )
264
+ if ($ mode === 'auto ' )
265
265
{
266
266
// Get the file extension so we can set the upload type
267
267
$ ext = $ this ->_getext ($ locpath );
268
268
$ mode = $ this ->_settype ($ ext );
269
269
}
270
270
271
- $ mode = ($ mode == 'ascii ' ) ? FTP_ASCII : FTP_BINARY ;
271
+ $ mode = ($ mode === 'ascii ' ) ? FTP_ASCII : FTP_BINARY ;
272
272
273
273
$ result = @ftp_put ($ this ->conn_id , $ rempath , $ locpath , $ mode );
274
274
@@ -301,22 +301,22 @@ function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL)
301
301
* @param string
302
302
* @return bool
303
303
*/
304
- function download ($ rempath , $ locpath , $ mode = 'auto ' )
304
+ public function download ($ rempath , $ locpath , $ mode = 'auto ' )
305
305
{
306
306
if ( ! $ this ->_is_conn ())
307
307
{
308
308
return FALSE ;
309
309
}
310
310
311
311
// Set the mode if not specified
312
- if ($ mode == 'auto ' )
312
+ if ($ mode === 'auto ' )
313
313
{
314
314
// Get the file extension so we can set the upload type
315
315
$ ext = $ this ->_getext ($ rempath );
316
316
$ mode = $ this ->_settype ($ ext );
317
317
}
318
318
319
- $ mode = ($ mode == 'ascii ' ) ? FTP_ASCII : FTP_BINARY ;
319
+ $ mode = ($ mode === 'ascii ' ) ? FTP_ASCII : FTP_BINARY ;
320
320
321
321
$ result = @ftp_get ($ this ->conn_id , $ locpath , $ rempath , $ mode );
322
322
@@ -343,7 +343,7 @@ function download($rempath, $locpath, $mode = 'auto')
343
343
* @param bool
344
344
* @return bool
345
345
*/
346
- function rename ($ old_file , $ new_file , $ move = FALSE )
346
+ public function rename ($ old_file , $ new_file , $ move = FALSE )
347
347
{
348
348
if ( ! $ this ->_is_conn ())
349
349
{
@@ -356,9 +356,7 @@ function rename($old_file, $new_file, $move = FALSE)
356
356
{
357
357
if ($ this ->debug == TRUE )
358
358
{
359
- $ msg = ($ move == FALSE ) ? 'ftp_unable_to_rename ' : 'ftp_unable_to_move ' ;
360
-
361
- $ this ->_error ($ msg );
359
+ $ this ->_error ('ftp_unable_to_ ' . ($ move == FALSE ? 'rename ' : 'move ' ));
362
360
}
363
361
return FALSE ;
364
362
}
@@ -376,7 +374,7 @@ function rename($old_file, $new_file, $move = FALSE)
376
374
* @param string
377
375
* @return bool
378
376
*/
379
- function move ($ old_file , $ new_file )
377
+ public function move ($ old_file , $ new_file )
380
378
{
381
379
return $ this ->rename ($ old_file , $ new_file , TRUE );
382
380
}
@@ -390,7 +388,7 @@ function move($old_file, $new_file)
390
388
* @param string
391
389
* @return bool
392
390
*/
393
- function delete_file ($ filepath )
391
+ public function delete_file ($ filepath )
394
392
{
395
393
if ( ! $ this ->_is_conn ())
396
394
{
@@ -421,7 +419,7 @@ function delete_file($filepath)
421
419
* @param string
422
420
* @return bool
423
421
*/
424
- function delete_dir ($ filepath )
422
+ public function delete_dir ($ filepath )
425
423
{
426
424
if ( ! $ this ->_is_conn ())
427
425
{
@@ -470,23 +468,13 @@ function delete_dir($filepath)
470
468
* @param string the permissions
471
469
* @return bool
472
470
*/
473
- function chmod ($ path , $ perm )
471
+ public function chmod ($ path , $ perm )
474
472
{
475
473
if ( ! $ this ->_is_conn ())
476
474
{
477
475
return FALSE ;
478
476
}
479
477
480
- // Permissions can only be set when running PHP 5
481
- if ( ! function_exists ('ftp_chmod ' ))
482
- {
483
- if ($ this ->debug == TRUE )
484
- {
485
- $ this ->_error ('ftp_unable_to_chmod ' );
486
- }
487
- return FALSE ;
488
- }
489
-
490
478
$ result = @ftp_chmod ($ this ->conn_id , $ perm , $ path );
491
479
492
480
if ($ result === FALSE )
@@ -509,7 +497,7 @@ function chmod($path, $perm)
509
497
* @access public
510
498
* @return array
511
499
*/
512
- function list_files ($ path = '. ' )
500
+ public function list_files ($ path = '. ' )
513
501
{
514
502
if ( ! $ this ->_is_conn ())
515
503
{
@@ -533,7 +521,7 @@ function list_files($path = '.')
533
521
* @param string path to destination - include the base folder with trailing slash
534
522
* @return bool
535
523
*/
536
- function mirror ($ locpath , $ rempath )
524
+ public function mirror ($ locpath , $ rempath )
537
525
{
538
526
if ( ! $ this ->_is_conn ())
539
527
{
@@ -543,24 +531,20 @@ function mirror($locpath, $rempath)
543
531
// Open the local file path
544
532
if ($ fp = @opendir ($ locpath ))
545
533
{
546
- // Attempt to open the remote file path.
547
- if ( ! $ this ->changedir ($ rempath , TRUE ))
534
+ // Attempt to open the remote file path and try to create it, if it doesn't exist
535
+ if ( ! $ this ->changedir ($ rempath , TRUE ) AND ( ! $ this -> mkdir ( $ rempath ) OR ! $ this -> changedir ( $ rempath )) )
548
536
{
549
- // If it doesn't exist we'll attempt to create the direcotory
550
- if ( ! $ this ->mkdir ($ rempath ) OR ! $ this ->changedir ($ rempath ))
551
- {
552
- return FALSE ;
553
- }
537
+ return FALSE ;
554
538
}
555
539
556
540
// Recursively read the local directory
557
541
while (FALSE !== ($ file = readdir ($ fp )))
558
542
{
559
- if (@is_dir ($ locpath .$ file ) && substr ( $ file, 0 , 1 ) ! = '. ' )
543
+ if (@is_dir ($ locpath .$ file ) && $ file[ 0 ] != = '. ' )
560
544
{
561
545
$ this ->mirror ($ locpath .$ file ."/ " , $ rempath .$ file ."/ " );
562
546
}
563
- elseif (substr ( $ file, 0 , 1 ) ! = ". " )
547
+ elseif ($ file[ 0 ] != = ". " )
564
548
{
565
549
// Get the file extension so we can se the upload type
566
550
$ ext = $ this ->_getext ($ file );
@@ -585,7 +569,7 @@ function mirror($locpath, $rempath)
585
569
* @param string
586
570
* @return string
587
571
*/
588
- function _getext ($ filename )
572
+ private function _getext ($ filename )
589
573
{
590
574
if (FALSE === strpos ($ filename , '. ' ))
591
575
{
@@ -606,7 +590,7 @@ function _getext($filename)
606
590
* @param string
607
591
* @return string
608
592
*/
609
- function _settype ($ ext )
593
+ private function _settype ($ ext )
610
594
{
611
595
$ text_types = array (
612
596
'txt ' ,
@@ -634,18 +618,16 @@ function _settype($ext)
634
618
* Close the connection
635
619
*
636
620
* @access public
637
- * @param string path to source
638
- * @param string path to destination
639
621
* @return bool
640
622
*/
641
- function close ()
623
+ public function close ()
642
624
{
643
625
if ( ! $ this ->_is_conn ())
644
626
{
645
627
return FALSE ;
646
628
}
647
629
648
- @ftp_close ($ this ->conn_id );
630
+ return @ftp_close ($ this ->conn_id );
649
631
}
650
632
651
633
// ------------------------------------------------------------------------
@@ -655,9 +637,9 @@ function close()
655
637
*
656
638
* @access private
657
639
* @param string
658
- * @return bool
640
+ * @return void
659
641
*/
660
- function _error ($ line )
642
+ private function _error ($ line )
661
643
{
662
644
$ CI =& get_instance ();
663
645
$ CI ->lang ->load ('ftp ' );
@@ -669,4 +651,4 @@ function _error($line)
669
651
// END FTP Class
670
652
671
653
/* End of file Ftp.php */
672
- /* Location: ./system/libraries/Ftp.php */
654
+ /* Location: ./system/libraries/Ftp.php */
0 commit comments