forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftp_fget_basic.phpt
42 lines (35 loc) · 916 Bytes
/
ftp_fget_basic.phpt
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
--TEST--
FTP ftp_fget file for both binary and ASCII transfer modes
--CREDITS--
Nathaniel McHugh
--EXTENSIONS--
ftp
pcntl
--FILE--
<?php
require 'server.inc';
$ftp = ftp_connect('127.0.0.1', $port);
if (!$ftp) die("Couldn't connect to the server");
var_dump(ftp_login($ftp, 'user', 'pass'));
//test simple text transfer
$fp = tmpfile();
var_dump(ftp_fget($ftp, $fp ,'a story.txt', FTP_ASCII));
fseek($fp, 0);
echo fgets($fp);
$position = ftell($fp);
//test binary data transfer
var_dump(ftp_fget($ftp, $fp, 'binary data.bin', FTP_BINARY));
fseek($fp, $position);
echo json_encode(fgets($fp)), "\n";
//test non-existent file request
ftp_fget($ftp, $fp ,'a warning.txt', FTP_ASCII);
//remove file
fclose($fp);
?>
--EXPECTF--
bool(true)
bool(true)
For sale: baby shoes, never worn.
bool(true)
"BINARYFoo\u0000Bar\r\n"
Warning: ftp_fget(): a warning: No such file or directory in %sftp_fget_basic.php on line %d