-
Notifications
You must be signed in to change notification settings - Fork 1
/
FTP.php
677 lines (604 loc) · 19 KB
/
FTP.php
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
<?php
// +----------------------------------------------------------------------+
// | Net_FTP2 Version 1.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2001-2005 Tobias Schlitt |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is available at through the world-wide-web at |
// | 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 world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Tobias Schlitt <toby@php.net> |
// +----------------------------------------------------------------------+
//
// $Id$
require_once 'Net/FTP2/Driver.php'
/**
* Net_FTP2 driver class for use of extFTP.
* This class wraps the extFTP functions into a class for use with Net_FTP2.
*
* @since 0.1
* @package Net_FTP2
* @author Tobias Schlitt <toby@php.net>
* @see http://www.schlitt.info
* @license http://www.php.net/license/3_0.txt PHP License 3.0
*/
class Net_FTP2_Driver_FTP extends Net_FTP2_Driver {
// {{{ $_resource
/**
* The FTP resource.
*
* @var resource
* @access private
* @since 0.1
*/
var $_resource;
// }}}
// {{{ Net_FTP2_Driver_FTP()
/**
* Constructor
* This is the constructor for Net_FTP2_Driver_FTP.
*
* @since 0.1
* @access public
* @param string $uri A URI to describe the the FTP connection in the format
* <protocol>://[<username>][:<password>][@]<host>[:<port>][/<directory]
* @param array $options An array of further options for the FTP connection.
* @return @void
*/
function Net_FTP2_Driver_FTP($uri, $options)
{
$this->Net_FTP_Driver($uri, $options);
}
// }}}
// {{{ checkDependencies()
/**
* Check if drivers dependencies are fulfilled.
*
* @since 0.1
* @access public
* @param
* @return bool True if dependencies are fulfilled, otherwise false.
*/
function checkDependencies($optional = false)
{
return (extension_loaded('ftp') || dl('ftp'));
}
// }}}
// {{{ ftp_alloc()
/**
* Sends an ALLO command to the remote FTP server to allocate filesize bytes of space. Returns TRUE on success, or FALSE on failure.
*
* @since 0.1
* @access public
* @param int $filesize
* @param string $result
* @return @boolean True on success, otherwise false.
*/
function ftp_alloc($filesize, $result = '')
{
return @ftp_alloc($this->_resource, $filesize, $result);
}
// }}}
// {{{ ftp_cdup()
/**
* Changes to the parent directory
*
* @since 0.1
* @access public
* @param
* @return @bool
*/
function ftp_cdup()
{
return @$this->ftp_chdir('..');
}
// }}}
// {{{ ftp_chdir()
/**
* Changes directories on a FTP server
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
* @since 0.1
* @access public
* @param string $directory
* @return @boolean True on success, otherwise false.
*/
function ftp_chdir($directory)
{
return @ftp_chdir($this->_resource, $directory);
}
// }}}
// {{{ ftp_chmod()
/**
* Set permissions on a file via FTP
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
* @since 0.1
* @access public
* @param int $mode
* @param string $filename
* @return @boolean True on success, otherwise false.
*/
function ftp_chmod($mode, $filename)
{
return @ftp_chmod($this->_resource, $mode, $filename);
}
// }}}
// {{{ ftp_close()
/**
* Closes an FTP connection
*
* @since 0.1
* @access public
* @return @boolean True on success, otherwise false.
*/
function ftp_close()
{
return @ftp_close($this->_resource);
}
// }}}
// {{{ ftp_connect()
/**
* Opens an FTP connection
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
* @since 0.1
* @param string $host The host to connect to.
* @param int $port The port to connect to.
* @param int $timeout Timeout for the connection to be opened.
* @access public
* @return @boolean True on success, otherwise false.
*/
function &ftp_connect($host, $port = 21, $timeout = 90)
{
$this->_resource = ftp_connect($this->_resource, $host, $port, $timeout);
return @$this->_resource;
}
// }}}
// {{{ ftp_delete()
/**
* Deletes a file on the FTP server
*
* @since 0.1
* @param string $path The path for the file to delete.
* @access public
* @return @boolean True on success, otherwise false.
*/
function ftp_delete($path)
{
return @ftp_delete($this->_resource, $path);
}
// }}}
// {{{ ftp_exec()
/**
* Requests execution of a program on the FTP server
*
* @since 0.1
* @param string $command The command to execute.
* @access public
* @return @boolean True on success, otherwise false.
*/
function ftp_exec($command)
{
return @ftp_exec($this->_resource, $command);
}
// }}}
// {{{ ftp_fget()
/**
* Downloads a file from the FTP server and saves to an open file.
*
* @since 0.1
* @param resource $handle Local file handler to write to.
* @param string $remote_file Path to the remote file to download.
* @param int $mode Mode to download the file (FTP_ASCII or FTP_BINARY).
* @param int $resumepos Position to resume the download (@since PHP 4.3.0).
* @access public
* @return @boolean True on success, otherwise false.
*/
function ftp_fget($handle, $remote_file, $mode, $resumepos = null)
{
return @ftp_fget($this->_resource, $handle, $remote_file, $mode, @$resumepos);
}
// }}}
// {{{ ftp_fput()
/**
* Uploads from an open file to the FTP server.
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @param string $remote_file Path to the remote file to upload to.
* @param resource $handle Local file handler to upload.
* @param int $mode Mode to download the file (FTP_ASCII or FTP_BINARY).
* @param int $resumepos Position to resume the upload (@since PHP 4.3.0).
* @access public
* @return @boolean True on success, otherwise false.
*/
function ftp_fput($remote_file, $handle, $mode, $startpos = null)
{
return @ftp_fput($this->_resource, $remote_file, $handle, $mode, @$startpos);
}
// }}}
// {{{ ftp_get()
/**
* Downloads a file from the FTP server
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @param string $local Local file path to write to.
* @param string $remote_file Path to the remote file to download.
* @param int $mode Mode to download the file (FTP_ASCII or FTP_BINARY).
* @param int $resumepos Position to resume the download (@since PHP 4.3.0).
* @access public
* @return @boolean True on success, otherwise false.
*/
function ftp_get($local_file, $remote_file, $mode, $resumepos = null)
{
return @ftp_get($this->_resource, $local_file, $remote_file, $mode, @$resumepos);
}
// }}}
// {{{ ftp_fput()
/**
* Uploads a file to the FTP server
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @param string $remote_file Path to the remote file to upload to.
* @param string $local_file Local file to upload.
* @param int $mode Mode to download the file (FTP_ASCII or FTP_BINARY).
* @param int $resumepos Position to resume the upload (@since PHP 4.3.0).
* @access public
* @return @boolean True on success, otherwise false.
*/
function ftp_put($remote_file, $handle, $mode, $startpos = null)
{
return @ftp_put($this->_resource, $remote_file, $handle, $mode, @$startpos);
}
// }}}
// {{{ ftp_login()
/**
* Logs in to an FTP connection
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @param string $username The username.
* @param string $password The password.
* @access public
* @return @boolean True on success, otherwise false.
*/
function ftp_login($username, $password)
{
return @ftp_login($this->_resource, $username, $password);
}
// }}}
// {{{ ftp_mdtm()
/**
* Returns the last modified time of the given file
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @param string $remote_file Path to the remote file.
* @access public
* @return @int Timestamp on success, otherwise -1.
*/
function ftp_mdtm($remote_file)
{
return @ftp_mdtm($this->_resource, $remote_file);
}
// }}}
// {{{ ftp_mkdir()
/**
* Creates a directory
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @param string $directory Path for the directory to create.
* @access public
* @return @mixed Name of the new directory on success, otherwise false.
*/
function ftp_mkdir($directory)
{
return @ ftp_mkdir($this->_resource, $directory);
}
// }}}
// {{{ ftp_nb_continue()
/**
* Continues retrieving/sending a file (non-blocking)
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @access public
* @return @int Returns FTP_FAILED or FTP_FINISHED or FTP_MOREDATA.
*/
function ftp_nb_continue()
{
return @ftp_nb_continue($this->_resource);
}
// }}}
// {{{ ftp_nb_fget()
/**
* Retrieves a file from the FTP server and writes it to an open file (non-blocking).
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @access public
* @param resource $handle Local file handler to write to.
* @param string $remote_file Path to the remote file to download.
* @param int $mode Mode to download the file (FTP_ASCII or FTP_BINARY).
* @param int $resumepos Position to resume the download (@since PHP 4.3.0).
* @access public
* @return @boolean True on success, otherwise false.
*/
function ftp_nb_fget($handle, $remote_file, $mode, $resumepos = null)
{
return @ftp_nb_fget($this->_resource, $handle, $remote_file, $mode, @$resumepos);
}
// }}}
// {{{ ftp_nb_put()
/**
* Retrieves a file from the FTP server and writes it to an open file (non-blocking)
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @param string $remote_file Path to the remote file to upload to.
* @param string $local_file Local file to upload.
* @param int $mode Mode to download the file (FTP_ASCII or FTP_BINARY).
* @param int $resumepos Position to resume the upload (@since PHP 4.3.0).
* @access public
* @return @boolean True on success, otherwise false.
*/
function ftp_nb_fput($remote_file, $handle, $mode, $startpos = null)
{
return @ftp_nb_fput($this->_resource, $remote_file, $handle, $mode, @$startpos);
}
// }}}
// {{{ ftp_nb_get()
/**
*
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @param string $local_file Local file path to write to.
* @param string $remote_file Path to the remote file to download.
* @param int $mode Mode to download the file (FTP_ASCII or FTP_BINARY).
* @param int $resumepos Position to resume the download (@since PHP 4.3.0).
* @access public
* @return @boolean True on success, otherwise false.
*/
function ftp_nb_get($local_file, $remote_file, $mode, $resumepos = null)
{
return @ftp_nb_get($this->_resource, $local_file, $remote_file, $mode, @$resumepos);
}
// }}}
// {{{ ftp_nb_put()
/**
* Stores a file on the FTP server (non-blocking).
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @param string $remote_file Path to the remote file to upload to.
* @param resource $local_file Local file to upload.
* @param int $mode Mode to download the file (FTP_ASCII or FTP_BINARY).
* @param int $resumepos Position to resume the upload (@since PHP 4.3.0).
* @access public
* @return @boolean True on success, otherwise false.
*/
function ftp_nb_put($remote_file, $local_file, $mode, $startpos = null)
{
return @ftp_nb_put($this->_resource, $remote_file, $local_file, $mode, @$startpos);
}
// }}}
// {{{ ftp_nlist()
/**
* Stores a file on the FTP server (non-blocking).
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @param string $directory The directory to list files from.
* @access public
* @return @mixed Array of filenames on success, otherwise false.
*/
function ftp_nlist ($directory)
{
return @ftp_nlist ($this->_resource, $directory);
}
// }}}
// {{{ ftp_pasv()
/**
* Turns passive mode on or off.
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @param bool $pasv True to turn on pasv mode, false to turn off.
* @access public
* @return @bool True on success, otherwise false.
*/
function ftp_pasv($pasv)
{
return @ftp_pasv($this->_resource, $pasv);
}
// }}}
// {{{ ftp_pwd()
/**
* Returns the current directory name.
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @access public
* @return @mixed String the current directory or false on error.
*/
function ftp_pwd()
{
return @ftp_pwd($this->_resource);
}
// }}}
// {{{ ftp_quit()
/**
* Closes an FTP connection (alias to ftp_close).
* This is one of the functions provided by extFTP, which must not be implemented by a driver since it's an alias to ftp_close('..').
*
*
*
* @since 0.1
* @access public
* @return @bool True on success, otherwise false.
*/
function ftp_quit()
{
return @$this->ftp_close();
}
// }}}
// {{{ ftp_rawlist()
/**
* Returns a detailed list of files in the given directory.
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @access public
* @param string $directory The directory to list files from.
* @return @mixed Array of file data on success, otherwise false.
*/
function ftp_rawlist($directory)
{
return @ftp_rawlist($this->_resource, $directory);
}
// }}}
// {{{ ftp_rename()
/**
* Renames a file on the FTP server.
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @access public
* @param string $from The file to rename.
* @param string $to The new name for the file.
* @return @bool True on success, otherwise false.
*/
function ftp_rename($from, $to)
{
return @ftp_rename($this->_resource, $from, $to);
}
// }}}
// {{{ ftp_rmdir()
/**
* Removes a directory.
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @access public
* @param string $directory The directory to remove.
* @return @bool True on success, otherwise false.
*/
function ftp_rmdir($directory)
{
return @ftp_rmdir($this->_resource, $directory);
}
// }}}
// {{{ ftp_site()
/**
* Sends a SITE command to the server.
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @access public
* @param string $cmd The command to send.
* @return @bool True on success, otherwise false.
*/
function ftp_site($cmd)
{
return @ftp_site($this->_resource, $cmd);
}
// }}}
// {{{ ftp_size()
/**
* Returns the size of the given file.
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @access public
* @param string $remote_file File to determine the size of.
* @return @int Size of the file in byte, -1 on error.
*/
function ftp_size($remote_file)
{
return @ftp_size($this->_resource, $remote_file);
}
// }}}
// {{{ ftp_ssl_connect()
/**
* Opens an Secure SSL-FTP connection.
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @access public
* @param string $host The host to connect to.
* @param int $port The port to connect to.
* @param int $timeout Timeout for the connection to be opened.
* @return @resource The FTP resource used inside the driver object.
*/
function &ftp_ssl_connect($host, $port = 21, $timeout = 90)
{
$this->_resource = @ftp_ssl_connect($host, $port = 21, $timeout = 90);
return @$this->_resource;
}
// }}}
// {{{ ftp_systype()
/**
* Returns the system type identifier of the remote FTP server.
* This is one of the functions provided by extFTP, which should be implemented by a driver.
*
*
*
* @since 0.1
* @access public
* @return @mixed String, the remote system type, or false on error.
*/
function ftp_systype()
{
return @ftp_systype($this->_resource);
}
}
?>