This file is indexed.

/usr/share/php/Net/FTP/Socket.php is in php-net-ftp 1.4.0a3-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * Net_FTP socket implementation of FTP functions.
 *
 * The functions in this file emulate the ext/FTP functions through
 * ext/Socket.
 *
 * PHP versions 4 and 5
 *
 * LICENSE: This source file is subject to version 3.0 of the PHP license
 * that is available through the world-wide-web at the following URI:
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to license@php.net so we can mail you a copy immediately.
 *
 * @category  Networking
 * @package   FTP
 * @author    Tobias Schlitt <toby@php.net>
 * @copyright 1997-2008 The PHP Group
 * @license   http://www.php.net/license/3_0.txt  PHP License 3.0
 * @version   CVS: $Id$
 * @link      http://pear.php.net/package/Net_FTP
 * @since     File available since Release 0.0.1
 */

/**
* Default FTP extension constants
*/
define('FTP_ASCII', 0);
define('FTP_TEXT', 0);
define('FTP_BINARY', 1);
define('FTP_IMAGE', 1);
define('FTP_TIMEOUT_SEC', 0);

/**
* What needs to be done overall?
*   #1 Install the rest of these functions
*   #2 Document better
*   #3 Alot of other things I don't remember
*/

/*
 * !!! NOTE !!!
 * Most of the comment's are "not working",
 * meaning they are not all up-to-date
 * !!! NOTE !!!
 */

/**
 * &resource ftp_connect ( string host [, int port [, int timeout ] ] );
 *
 * Opens an FTP connection and return resource or false on failure.
 *
 * FTP Success respons code: 220
 *
 * @param string $host    Host to connect to
 * @param int    $port    Optional, port to connect to
 * @param int    $timeout Optional, seconds until function timeouts
 *
 * @todo The FTP extension has ftp_get_option() function which returns the
 * timeout variable. This function needs to be created and contain it as
 * static variable.
 * @todo The FTP extension has ftp_set_option() function which sets the
 * timeout variable. This function needs to be created and called here.
 * @access public
 * @return &resource
 */
if (!function_exists('ftp_connect')) {
    function &ftp_connect($host, $port = 21, $timeout = 90)
    {
        $false = false; // We are going to return refrence (E_STRICT)

        if (!is_string($host) || !is_integer($port) || !is_integer($timeout)) {
            return $false;
        }

        $iError = 0;
        $sError = '';

        $control                        = @fsockopen($host, $port, $iError, $sError,
            $timeout);
        $GLOBALS['_NET_FTP']['timeout'] = $timeout;

        if (!is_resource($control)) {
            return $false;
        }

        stream_set_blocking($control, true);
        stream_set_timeout($control, $timeout);

        do {
            $content[] = fgets($control, 8129);
            $array     = socket_get_status($control);
        } while ($array['unread_bytes'] > 0);

        if (substr($content[count($content)-1], 0, 3) == 220) {
            return $control;
        }

        return $false;
    }
}

/**
 * boolean ftp_login ( resource stream, string username, string password );
 *
 * Logs in to an given FTP connection stream.
 * Returns TRUE on success or FALSE on failure.
 *
 * NOTE:
 *       Username and password are *not* optional. Function will *not*
 *       assume "anonymous" if username and/or password is empty
 *
 * FTP Success respons code: 230
 *
 * @param resource &$control FTP resource to login to
 * @param string   $username FTP Username to be used
 * @param string   $password FTP Password to be used
 *
 * @access public
 * @return   boolean
 */
if (!function_exists('ftp_login')) {
    function ftp_login(&$control, $username, $password)
    {
        if (!is_resource($control) || is_null($username)) {
            return false;
        }

        fputs($control, 'USER '.$username."\r\n");
        $contents = array();
        do {
            $contents[] = fgets($control, 8192);
            $array      = socket_get_status($control);
        } while ($array['unread_bytes'] > 0);

        if (substr($contents[count($contents)-1], 0, 3) != 331) {
            return false;
        }

        fputs($control, 'PASS '.$password."\r\n");
        $contents = array();
        do {
            $contents[] = fgets($control, 8192);
            $array      = socket_get_status($control);
        } while ($array['unread_bytes']);

        if (substr($contents[count($contents)-1], 0, 3) == 230) {
            return true;
        }

        trigger_error('ftp_login() [<a href="function.ftp-login">function.ftp-login'.
            '</a>]: '.$contents[count($contents)-1], E_USER_WARNING);

        return false;
    }
}

/**
 * boolean ftp_quit ( resource stream );
 *
 * Closes FTP connection.
 * Returns TRUE or FALSE on error.
 *
 * NOTE: The PHP function ftp_quit is *alias* to ftp_close, here it is
 * the *other-way-around* ( ftp_close() is alias to ftp_quit() ).
 *
 * NOTE:
 *       resource is set to null since unset() can't unset the variable.
 *
 * @param resource &$control FTP resource
 *
 * @access public
 * @return boolean
 */
if (!function_exists('ftp_quit')) {
    function ftp_quit(&$control)
    {
        if (!is_resource($control)) {
            return false;
        }

        fputs($control, 'QUIT'."\r\n");
        fclose($control);
        $control = null;
        return true;
    }
}

/**
 * Alias to ftp_quit()
 *
 * @param resource &$control FTP resource
 *
 * @see ftp_quit()
 * @access public
 * @return boolean
 */
if (!function_exists('ftp_close')) {
    function ftp_close(&$control)
    {
        return ftp_quit($control);
    }
}

/**
 * string ftp_pwd ( resource stream );
 *
 * Gets the current directory name.
 * Returns the current directory.
 *
 * Needs data connection: NO
 * Success response code: 257
 *
 * @param resource &$control FTP resource
 *
 * @access public
 * @return string
 */
if (!function_exists('ftp_pwd')) {
    function ftp_pwd(&$control)
    {
        if (!is_resource($control)) {
            return $control;
        }

        fputs($control, 'PWD'."\r\n");

        $content = array();
        do {
            $content[] = fgets($control, 8192);
            $array     = socket_get_status($control);
        } while ($array['unread_bytes'] > 0);

        if (substr($cont = $content[count($content)-1], 0, 3) == 257) {
            $pos  = strpos($cont, '"')+1;
            $pos2 = strrpos($cont, '"') - $pos;
            $path = substr($cont, $pos, $pos2);
            return $path;
        }

        return false;
    }
}

/**
 * boolean ftp_chdir ( resource stream, string directory );
 *
 * Changes the current directory to the specified directory.
 * Returns TRUE on success or FALSE on failure.
 *
 * FTP success response code: 250
 * Needs data connection: NO
 *
 * @param resource &$control FTP stream
 * @param string   $pwd      Directory name
 *
 * @access public
 * @return boolean
 */
if (!function_exists('ftp_chdir')) {
    function ftp_chdir(&$control, $pwd)
    {
        if (!is_resource($control) || !is_string($pwd)) {
            return false;
        }

        fputs($control, 'CWD '.$pwd."\r\n");
        $content = array();
        do {
            $content[] = fgets($control, 8192);
            $array     = socket_get_status($control);
        } while ($array['unread_bytes'] > 0);

        if (substr($content[count($content)-1], 0, 3) == 250) {
            return true;
        }

        trigger_error('ftp_chdir() [<a
            href="function.ftp-chdir">function.ftp-chdir</a>]:
                ' .$content[count($content)-1], E_USER_WARNING);

        return false;
    }
}

$_NET_FTP                = array();
$_NET_FTP['USE_PASSIVE'] = false;
$_NET_FTP['DATA']        = null;

/**
 * boolean ftp_pasv ( resource stream, boolean passive );
 *
 * Toggles passive mode ON/OFF.
 * Returns TRUE on success or FALSE on failure.
 *
 * Comment:
 *       Although my lack of C knowlege I checked how the PHP FTP extension
 *       do things here. Seems like they create the data connection and store
 *       it in object for other functions to use.
 *       This is now done here.
 *
 * FTP success response code: 227
 *
 * @param stream  &$control FTP stream
 * @param boolean $pasv     True to switch to passive, false for active mode
 *
 * @access public
 * @return boolean
 */
if (!function_exists('ftp_pasv')) {
    function ftp_pasv(&$control, $pasv)
    {
        if (!is_resource($control) || !is_bool($pasv)) {
            return false;
        }

        // If data connection exists, destroy it
        if (isset($GLOBALS['_NET_FTP']['DATA'])) {
            fclose($GLOBALS['_NET_FTP']['DATA']);
            $GLOBALS['_NET_FTP']['DATA'] = null;

            do {
                fgets($control, 16);
                $array = socket_get_status($control);
            } while ($array['unread_bytes'] > 0);
        }

        // Are we suppost to create active or passive connection?
        if (!$pasv) {
            $GLOBALS['_NET_FTP']['USE_PASSIVE'] = false;
            // Pick random "low bit"
            $low = rand(39, 250);
            // Pick random "high bit"
            $high = rand(39, 250);
            // Lowest  possible port would be; 10023
            // Highest possible port would be; 64246

            $port = ($low<<8)+$high;
            $ip   = str_replace('.', ',', $_SERVER['SERVER_ADDR']);
            $s    = $ip.','.$low.','.$high;

            $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
            if (is_resource($socket)) {
                if (socket_bind($socket, '0.0.0.0', $port)) {
                    if (socket_listen($socket)) {
                        $GLOBALS['_NET_FTP']['DATA'] = &$socket;
                        fputs($control, 'PORT '.$s."\r\n");
                        $line = fgets($control, 512);
                        if (substr($line, 0, 3) == 200) {
                            return true;
                        }
                    }
                }
            }
            return false;
        }

        // Since we are here, we are suppost to create passive data connection.
        fputs($control, 'PASV' ."\r\n");

        $content = array();
        do {
            $content[] = fgets($control, 128);
            $array     = socket_get_status($control);
        } while ($array['unread_bytes']);

        if (substr($cont = $content[count($content)-1], 0, 3) != 227) {
            return false;
        }

        $pos    = strpos($cont, '(')+1;
        $pos2   = strrpos($cont, ')')-$pos;
        $string = substr($cont, $pos, $pos2);

        $array = explode(',', $string);

        // IP we are connecting to
        $ip = $array[0]. '.' .$array[1]. '.' .$array[2]. '.' .$array[3];

        // Port ( 256*lowbit + highbit
        $port = ($array[4] << 8)+$array[5];

        // Our data connection
        $iError = 0;
        $sError = '';
        $data   = fsockopen($ip, $port, $iError, $sError,
            $GLOBALS['_NET_FTP']['timeout']);

        if (is_resource($data)) {
            $GLOBALS['_NET_FTP']['USE_PASSIVE'] = true;
            $GLOBALS['_NET_FTP']['DATA']        = &$data;
            stream_set_blocking($data, true);
            stream_set_timeout($data, $GLOBALS['_NET_FTP']['timeout']);

            return true;
        }

        return false;
    }
}

/**
 * array ftp_rawlist ( resource stream, string directory [,bool recursive] );
 *
 * Returns a detailed list of files in the given directory.
 *
 * Needs data connection: YES
 *
 * @param integer &$control  FTP resource
 * @param string  $pwd       Path to retrieve
 * @param boolean $recursive Optional, retrieve recursive listing
 *
 * @todo Enable the recursive feature.
 * @access public
 * @return   array
 */
if (!function_exists('ftp_rawlist')) {
    function ftp_rawlist(&$control, $pwd, $recursive = false)
    {
        if (!is_resource($control) || !is_string($pwd)) {
            return false;
        }

        if (!isset($GLOBALS['_NET_FTP']['DATA']) ||
            !is_resource($GLOBALS['_NET_FTP']['DATA'])) {

            ftp_pasv($control, $GLOBALS['_NET_FTP']['USE_PASSIVE']);

        }
        fputs($control, 'LIST '.$pwd."\r\n");

        $msg = fgets($control, 512);
        if (substr($msg, 0, 3) == 425) {
            return false;
        }

        $data = &$GLOBALS['_NET_FTP']['DATA'];
        if (!$GLOBALS['_NET_FTP']['USE_PASSIVE']) {
            $data = &socket_accept($data);
        }

        $content = array();

        switch ($GLOBALS['_NET_FTP']['USE_PASSIVE']) {
        case true:
            while (true) {
                $string = rtrim(fgets($data, 1024));

                if ($string=='') {
                    break;
                }

                $content[] = $string;
            }

            fclose($data);
            break;

        case false:
            $string = socket_read($data, 1024, PHP_BINARY_READ);

            $content = explode("\n", $string);
            unset($content[count($content)-1]);

            socket_close($GLOBALS['_NET_FTP']['DATA']);
            socket_close($data);
            break;
        }

        $data = $GLOBALS['_NET_FTP']['DATA'] = null;

        fgets($control, 1024);
        return $content;
    }
}

/**
 * string ftp_systype ( resource stream );
 *
 * Gets system type identifier of remote FTP server
 * Returns the remote system type
 *
 * @param resource &$control FTP resource
 *
 * @access public
 * @return string
 */
if (!function_exists('ftp_systype')) {
    function ftp_systype(&$control)
    {
        if (!is_resource($control)) {
            return false;
        }

        fputs($control, 'SYST'."\r\n");
        $line = fgets($control, 256);

        if (substr($line, 0, 3) != 215) {
            return false;
        }

        $os = substr($line, 4, strpos($line, ' ', 4)-4);
        return $os;
    }
}

/**
 * boolean ftp_alloc ( resource stream, integer bytes [, string &message ] );
 *
 * Allocates space for a file to be uploaded
 * Return TRUE on success or FALSE on failure
 *
 * NOTE; Many FTP servers do not support this command and/or don't need it.
 *
 * FTP success respons key: Belive it's 200
 * Needs data connection: NO
 *
 * @param resource &$control FTP stream
 * @param integer  $int      Space to allocate
 * @param string   &$msg     Optional, textual representation of the servers response
 *                           will be returned by reference
 *
 * @access public
 * @return   boolean
 */
if (!function_exists('ftp_alloc')) {
    function ftp_alloc(&$control, $int, &$msg = null)
    {
        if (!is_resource($control) || !is_integer($int)) {
            return false;
        }

        fputs($control, 'ALLO '.$int.' R '.$int."\r\n");

        $msg = rtrim(fgets($control, 256));

        $code = substr($msg, 0, 3);
        if ($code == 200 || $code == 202) {
            return true;
        }

        return false;
    }
}

/**
 * bool ftp_put ( resource stream, string remote_file, string local_file,
 *               int mode [, int startpos ] );
 *
 * Uploads a file to the FTP server
 * Returns TRUE on success or FALSE on failure.
 *
 * NOTE:
 *       The transfer mode specified must be either FTP_ASCII or FTP_BINARY.
 *
 * @param resource &$control FTP stream
 * @param string   $remote   Remote file to write
 * @param string   $local    Local file to upload
 * @param integer  $mode     Upload mode, FTP_ASCI || FTP_BINARY
 * @param integer  $pos      Optional, start upload at position
 *
 * @access public
 * @return boolean
 */
if (!function_exists('ftp_put')) {
    function ftp_put(&$control, $remote, $local, $mode, $pos = 0)
    {
        if (!is_resource($control) || !is_readable($local) ||
            !is_integer($mode) || !is_integer($pos)) {
            return false;
        }

        $types   = array (
            0 => 'A',
            1 => 'I'
        );
        $windows = array (
            0 => 't',
            1 => 'b'
        );

        /**
        * TYPE values:
        *       A ( ASCII  )
        *       I ( BINARY )
        *       E ( EBCDIC )
        *       L ( BYTE   )
        */

        if (!isset($GLOBALS['_NET_FTP']['DATA']) ||
            !is_resource($GLOBALS['_NET_FTP']['DATA'])) {
            ftp_pasv($control, $GLOBALS['_NET_FTP']['USE_PASSIVE']);
        }

        // Establish data connection variable
        $data = &$GLOBALS['_NET_FTP']['DATA'];

        // Decide TYPE to use
        fputs($control, 'TYPE '.$types[$mode]."\r\n");
        $line = fgets($control, 256); // "Type set to TYPE"
        if (substr($line, 0, 3) != 200) {
            return false;
        }

        fputs($control, 'STOR '.$remote."\r\n");
        sleep(1);
        $line = fgets($control, 256); // "Opening TYPE mode data connect."

        if (substr($line, 0, 3) != 150) {
            return false;
        }

        // Creating resource to $local file
        $fp = fopen($local, 'r'. $windows[$mode]);
        if (!is_resource($fp)) {
            $fp = null;
            return false;
        }

        // Loop throu that file and echo it to the data socket
        $i = 0;
        switch ($GLOBALS['_NET_FTP']['USE_PASSIVE']) {
        case false:
            $data = &socket_accept($data);
            while (!feof($fp)) {
                $i += socket_write($data, fread($fp, 10240), 10240);
            }
            socket_close($data);
            break;

        case true:
            while (!feof($fp)) {
                $i += fputs($data, fread($fp, 10240), 10240);
            }
            fclose($data);
            break;
        }

        $data = null;
        do {
            $line = fgets($control, 256);
        } while (substr($line, 0, 4) != "226 ");
        return true;
    }
}

/**
 * Retrieve a remote file to a local file
 * Returns TRUE on success or FALSE on failure
 *
 * @param integer &$control Stream ID
 * @param string  $local    Local filename
 * @param string  $remote   Remote filename
 * @param integer $mode     Transfer mode (FTP_ASCII or FTP_BINARY)
 * @param integer $resume   Resume the file transfer or not
 *
 * @access public
 * @return boolean
 */
if (!function_exists('ftp_get')) {
    function ftp_get(&$control, $local, $remote, $mode, $resume = 0)
    {
        if (!is_resource($control) || !is_writable(dirname($local)) ||
            !is_integer($mode) || !is_integer($resume)) {
            return false;
        }
        $types   = array (
            0 => 'A',
            1 => 'I'
        );
        $windows = array (
            0 => 't',
            1 => 'b'
        );

        if (!isset($GLOBALS['_NET_FTP']['DATA']) ||
            !is_resource($GLOBALS['_NET_FTP'][ 'DATA'])) {
            ftp_pasv($control, $GLOBALS['_NET_FTP']['USE_PASSIVE']);
        }

        fputs($control, 'TYPE '.$types[$mode]."\r\n");
        $line = fgets($control, 256);
        if (substr($line, 0, 3) != 200) {
            return false;
        }

        $fp = fopen($local, 'w'.$windows[$mode]);
        if (!is_resource($fp)) {
            $fp = null;
            return false;
        }
        return true;
    }
}

/**
 * Changes to the parent directory
 * Returns TRUE on success or FALSE on failure
 *
 * @param integer &$control Stream ID
 *
 * @access public
 * @return boolean
 */
if (!function_exists('ftp_cdup')) {
    function ftp_cdup(&$control)
    {
        fputs($control, 'CDUP'."\r\n");
        $line = fgets($control, 256);

        if (substr($line, 0, 3) != 250) {
            return false;
        }

        return true;
    }
}

/**
 * Set permissions on a file via FTP
 * Returns the new file permission on success or false on error
 *
 * NOTE: This command is *not* supported by the standard
 * NOTE: This command not ready!
 *
 * @param integer &$control Stream ID
 * @param integer $mode     Octal value
 * @param string  $file     File to change permissions on
 *
 * @todo Figure out a way to chmod files via FTP
 * @access public
 * @return integer
 */
if (!function_exists('ftp_chmod')) {
    function ftp_chmod(&$control, $mode, $file)
    {
        if (!is_resource($control) || !is_integer($mode) || !is_string($file)) {
            return false;
        }

        // chmod not in the standard, proftpd doesn't recognize it
        // use SITE CHMOD?
        fputs($control, 'SITE CHMOD '.$mode. ' ' .$file."\r\n");
        $line = fgets($control, 256);

        if (substr($line, 0, 3) == 200) {
            return $mode;
        }

        trigger_error('ftp_chmod() [<a
            href="function.ftp-chmod">function.ftp-chmod</a>]: ' .
            rtrim($line), E_USER_WARNING);
        return false;
    }
}

/**
 * Deletes a file on the FTP server
 * Returns TRUE on success or FALSE on failure
 *
 * @param integer &$control Stream ID
 * @param string  $path     File to delete
 *
 * @access public
 * @return boolean
 */
if (!function_exists('ftp_delete')) {
    function ftp_delete(&$control, $path)
    {
        if (!is_resource($control) || !is_string($path)) {
            return false;
        }

        fputs($control, 'DELE '.$path."\r\n");
        $line = fgets($control, 256);

        if (substr($line, 0, 3) == 250) {
            return true;
        }

        return false;
    }
}

/**
 * Requests execution of a program on the FTP server
 * NOTE; SITE EXEC is *not* supported by the standart
 * Returns TRUE on success or FALSE on error
 *
 * @param integer &$control Stream ID
 * @param string  $cmd      Command to send
 *
 * @access public
 * @todo Look a littlebit better into this
 * @return boolean
 */
if (!function_exists('ftp_exec')) {
    function ftp_exec(&$control, $cmd)
    {
        if (!is_resource($control) || !is_string($cmd)) {
            return false;
        }

        // Command not defined in the standart
        // proftpd doesn't recognize SITE EXEC (only help,chgrp,chmod and ratio)
        fputs($control, 'SITE EXEC '.$cmd."\r\n");
        $line = fgets($control, 256);

        // php.net/ftp_exec uses respons code 200 to verify if command was sent
        // successfully or not, so we'll just do the same
        if (substr($line, 0, 3) == 200) {
            return true;
        }

        return false;
    }
}
?>