Is it possible to download the files in a directory using curl in PHP?

Recommended Answers

Yes, you can. Through the FTP protocol. Here's a sample directory listing, then with regards to downloading the contents, you can use ftp commands to download the contents after parsing the directory list

$curl = curl_init();
$ftpURL = "ftp://localhost/"
$ftpUsername = "username"
$ftpPassword = "password" …
Jump to Post

All 2 Replies

Yes, you can. Through the FTP protocol. Here's a sample directory listing, then with regards to downloading the contents, you can use ftp commands to download the contents after parsing the directory list

$curl = curl_init();
$ftpURL = "ftp://localhost/"
$ftpUsername = "username"
$ftpPassword = "password"

curl_setopt($curl, CURLOPT_URL, $ftpURL);
curl_setopt($curl, CURLOPT_USERPWD, $ftpUsername . ":" . $ftpPassword);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec ($curl);

//Parse your result then use ftp to download the content
Member Avatar

Are these files on your server?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.