ftp_get_basic.phpt 979 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. --TEST--
  2. FTP ftp_get file for both binary and ASCII transfer modes
  3. --CREDITS--
  4. Nathaniel McHugh
  5. --EXTENSIONS--
  6. ftp
  7. pcntl
  8. --FILE--
  9. <?php
  10. require 'server.inc';
  11. $ftp = ftp_connect('127.0.0.1', $port);
  12. if (!$ftp) die("Couldn't connect to the server");
  13. var_dump(ftp_login($ftp, 'user', 'pass'));
  14. //test simple text transfer
  15. $tmpfname = tempnam(__DIR__, "ftp_test");
  16. var_dump(ftp_get($ftp, $tmpfname ,'a story.txt', FTP_ASCII));
  17. echo file_get_contents($tmpfname);
  18. unlink($tmpfname);
  19. //test binary data transfer
  20. $tmpfname = tempnam(__DIR__, "ftp_test");
  21. var_dump(ftp_get($ftp, $tmpfname, 'binary data.bin', FTP_BINARY));
  22. echo json_encode(file_get_contents($tmpfname)), "\n";
  23. unlink($tmpfname);
  24. //test non-existent file request
  25. ftp_get($ftp, $tmpfname ,'a warning.txt', FTP_ASCII);
  26. ?>
  27. --EXPECTF--
  28. bool(true)
  29. bool(true)
  30. For sale: baby shoes, never worn.
  31. bool(true)
  32. "BINARYFoo\u0000Bar\r\n"
  33. Warning: ftp_get(): a warning: No such file or directory in %sftp_get_basic.php on line %d