xref: /PHP-8.0/ext/ftp/tests/ftp_get_basic.phpt (revision 26dfce7f)
1--TEST--
2FTP ftp_get file for both binary and ASCII transfer modes
3--CREDITS--
4Nathaniel McHugh
5--SKIPIF--
6<?php
7require 'skipif.inc';
8?>
9--FILE--
10<?php
11require 'server.inc';
12
13$ftp = ftp_connect('127.0.0.1', $port);
14if (!$ftp) die("Couldn't connect to the server");
15
16var_dump(ftp_login($ftp, 'user', 'pass'));
17
18//test simple text transfer
19$tmpfname = tempnam(__DIR__, "ftp_test");
20var_dump(ftp_get($ftp, $tmpfname ,'a story.txt', FTP_ASCII));
21echo file_get_contents($tmpfname);
22unlink($tmpfname);
23
24//test binary data transfer
25$tmpfname = tempnam(__DIR__, "ftp_test");
26var_dump(ftp_get($ftp, $tmpfname, 'binary data.bin', FTP_BINARY));
27var_dump(urlencode(file_get_contents($tmpfname)));
28unlink($tmpfname);
29
30//test non-existent file request
31ftp_get($ftp, $tmpfname ,'a warning.txt', FTP_ASCII);
32?>
33--EXPECTF--
34bool(true)
35bool(true)
36For sale: baby shoes, never worn.
37bool(true)
38string(21) "BINARYFoo%00Bar%0D%0A"
39
40Warning: ftp_get(): a warning: No such file or directory  in %sftp_get_basic.php on line %d
41