curl_ftp_pasv.phpt 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --TEST--
  2. Test curl_exec() function with basic functionality
  3. --SKIPIF--
  4. <?php
  5. if (!extension_loaded("curl")) exit("skip curl extension not loaded");
  6. if (false === getenv('PHP_CURL_FTP_REMOTE_SERVER')) exit("skip PHP_CURL_FTP_REMOTE_SERVER env variable is not defined");
  7. if (false === getenv('PHP_CURL_FTP_REMOTE_USER')) exit("skip PHP_CURL_FTP_REMOTE_USER env variable is not defined");
  8. if (false === getenv('PHP_CURL_FTP_REMOTE_PASSWD')) exit("skip PHP_CURL_FTP_REMOTE_PASSWD env variable is not defined");
  9. ?>
  10. --FILE--
  11. <?php
  12. $host = getenv('PHP_CURL_FTP_REMOTE_SERVER');
  13. $username = getenv('PHP_CURL_FTP_REMOTE_USER');
  14. $password = getenv('PHP_CURL_FTP_REMOTE_PASSWD');
  15. // FTP this script to a server
  16. $fp = fopen ( __FILE__ , "r" );
  17. $url = "ftp://$username:$password@$host/test.phpt" ;
  18. $ch = curl_init ();
  19. // enable below to get the output in verbose mode.
  20. // curl_setopt ( $ch , CURLOPT_VERBOSE, 1 );
  21. /* Without enabling SKIP_PASV_IP flag, the following output will be seen..
  22. < 227 Entering Passive Mode (10,5,80,146,100,199)
  23. * Trying 10.5.80.146... * connected
  24. * Connecting to 10.5.80.146 (10.5.80.146) port 25799
  25. */
  26. /* After enabling SKIP_PASV_IP flag, the following output will be seen..
  27. < 227 Entering Passive Mode (10,5,80,146,50,229)
  28. * Skips 10.5.80.146 for data connection, uses 10.5.80.146 instead
  29. * Trying 10.5.80.146... * connected
  30. */
  31. curl_setopt ( $ch , CURLOPT_URL, $url );
  32. curl_setopt ( $ch , CURLOPT_TRANSFERTEXT, 1 );
  33. //force passive connection
  34. curl_setopt ( $ch , CURLOPT_FTP_USE_EPSV, 0 );
  35. curl_setopt ( $ch , CURLOPT_FTP_SKIP_PASV_IP, 1 );
  36. // mark the file for upload..
  37. curl_setopt ( $ch , CURLOPT_INFILE, $fp );
  38. curl_setopt ( $ch , CURLOPT_INFILESIZE, filesize(__FILE__) );
  39. curl_setopt ( $ch , CURLOPT_PUT, 1 );
  40. curl_setopt ( $ch , CURLOPT_UPLOAD, 1 );
  41. $result = curl_exec ( $ch );
  42. var_dump ( $result );
  43. curl_close ( $ch );
  44. ?>
  45. ===DONE===
  46. --EXPECT--
  47. bool(true)
  48. ===DONE===