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