xref: /PHP-8.1/ext/ftp/tests/ftp_get_basic.phpt (revision ea256a21)
1--TEST--
2FTP ftp_get 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$tmpfname = tempnam(__DIR__, "ftp_test");
19var_dump(ftp_get($ftp, $tmpfname ,'a story.txt', FTP_ASCII));
20echo file_get_contents($tmpfname);
21unlink($tmpfname);
22
23//test binary data transfer
24$tmpfname = tempnam(__DIR__, "ftp_test");
25var_dump(ftp_get($ftp, $tmpfname, 'binary data.bin', FTP_BINARY));
26echo json_encode(file_get_contents($tmpfname)), "\n";
27unlink($tmpfname);
28
29//test non-existent file request
30ftp_get($ftp, $tmpfname ,'a warning.txt', FTP_ASCII);
31?>
32--EXPECTF--
33bool(true)
34bool(true)
35For sale: baby shoes, never worn.
36bool(true)
37"BINARYFoo\u0000Bar\r\n"
38
39Warning: ftp_get(): a warning: No such file or directory  in %sftp_get_basic.php on line %d
40