xref: /php-src/ext/ftp/tests/ftp_fget_basic.phpt (revision ea256a21)
1--TEST--
2FTP ftp_fget file for both binary and ASCII transfer modes
3--CREDITS--
4Nathaniel McHugh
5--EXTENSIONS--
6ftp
7pcntl
8--FILE--
9<?php
10require 'server.inc';
11
12$ftp = ftp_connect('127.0.0.1', $port);
13if (!$ftp) die("Couldn't connect to the server");
14
15var_dump(ftp_login($ftp, 'user', 'pass'));
16
17//test simple text transfer
18$fp = tmpfile();
19var_dump(ftp_fget($ftp, $fp ,'a story.txt', FTP_ASCII));
20fseek($fp, 0);
21echo fgets($fp);
22
23$position = ftell($fp);
24//test binary data transfer
25var_dump(ftp_fget($ftp, $fp, 'binary data.bin', FTP_BINARY));
26fseek($fp, $position);
27echo json_encode(fgets($fp)), "\n";
28
29//test non-existent file request
30ftp_fget($ftp, $fp ,'a warning.txt', FTP_ASCII);
31
32//remove file
33fclose($fp);
34?>
35--EXPECTF--
36bool(true)
37bool(true)
38For sale: baby shoes, never worn.
39bool(true)
40"BINARYFoo\u0000Bar\r\n"
41
42Warning: ftp_fget(): a warning: No such file or directory  in %sftp_fget_basic.php on line %d
43