Downloads from an FTP server to which the connection is made using the given
$username and
$password
arguments, one or more files specified by the
$urls argument, saves the downloaded files (with their original
name) to the path specified by the
$path argument, and executes the callback function specified by the
$callback argument for each and every request, as soon as a request finishes.
Downloads are streamed (bytes downloaded are directly written to disk) removing the unnecessary strain from your
server of reading files into memory first, and then writing them to disk.
This method will automatically set the following options:
-
CURLINFO_HEADER_OUT - TRUE
-
CURLOPT_BINARYTRANSFER - TRUE
-
CURLOPT_HEADER - TRUE
-
CURLOPT_FILE
...and will unset the following options:
-
CURLOPT_CUSTOMREQUEST
-
CURLOPT_HTTPGET
-
CURLOPT_NOBODY
-
CURLOPT_POST
-
CURLOPT_POSTFIELDS
Files are downloaded preserving their name so you may want to check that, if you are downloading more files
having the same name (either from the same, or from different servers)!
Multiple requests are processed asynchronously, in parallel, and the callback function is called for each and every
request, as soon as a request finishes. The number of parallel requests to be constantly processed, at all times,
can be set through the {@link threads} property. See also the {@link pause_interval} property.
Note that requests may not finish in the same order as initiated!
the callback function to be executed for each and every
request, as soon as a request finishes
the callback function receives as argument an object with 4 properties
(info, header, body and response)
function mycallback($result) {
everything went well at cURL level
if ($result->response[1] == CURLE_OK) {
if server responded with code 200 (meaning that everything went well)
see http://httpstatus.es/ for a list of possible response codes
if ($result->info['http_code'] == 200) {
see all the returned data
print_r('
');
print_r($result);
show the server's response code
} else die('Server responded with code ' . $result->info['http_code']);
something went wrong
($result still contains all data that could be gathered)
} else die('cURL responded with: ' . $result->response[0]);
}
include the Zebra_cURL library
require 'path/to/Zebra_cURL';
instantiate the Zebra_cURL object
$curl = new Zebra_cURL();
connect to the FTP server using the given credential, download a file to a given location and
execute the "mycallback" function for each request, as soon as it finishes
$curl->ftp_download('ftp://somefile.ext', 'destination/path', 'username', 'password', 'mycallback');