简体   繁体   中英

cURL : Display/get text file contents using FTP with PHP

I need some help, I have a ftp access and my problem is I want to display or get the content of a specific file since I will use as a variable in php. How is it possible? I have this code but it just show the content of the directory.

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "ftp://$HOST");
curl_setopt($curl, CURLOPT_USERPWD, "$USER:$PASS");
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1) ;
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'CWD /$PATH'); 
curl_exec($curl);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'MLSD');
$ftp_result=curl_exec($curl);
echo $ftp_result;

Try

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "ftp://$HOST/$PATH");
curl_setopt($curl, CURLOPT_USERPWD, "$USER:$PASS");
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
$ftp_result=curl_exec($curl);
echo $ftp_result;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM