curl_ftp_pasv.phpt 1.9 KB

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