Using FTP from PHP CURL
I searched for a way to change working directory also, but couldn't find anything.
What ultimately worked for me was including the folder in the CURLOPT_URL
. Additionally, the folder alone wasn't enough, I had to include a trailing forward slash /
.
So if what worked for me will work for you, then setting the following url structure and CURLOPT_FTPLISTONLY
should get you the contents of bussys/
.
curl_setopt($ch, CURLOPT_URL, 'ftp://ftp.microsoft.com/bussys/');curl_setopt($ch, CURLOPT_FTPLISTONLY, TRUE);
And I didn't need the CURLOPT_POSTQUOTE
CWD
option to get the nested directories contents.
If you want to work with curl, use CURLOPT_CUSTOMREQUEST options.
See below example code.
$curl = curl_init();curl_setopt($curl, CURLOPT_URL, "ftp://192.168.0.129");curl_setopt($curl, CURLOPT_USERPWD, "sru:sru");curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1) ;curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'CWD /a'); // change directorycurl_exec($curl);curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'MLSD'); // get directory list$ftp_result=curl_exec($curl);echo $ftp_result;
It returns
type=dir;modify=20130319024302; test
test is sub directory of a.
I think you have to use ftp_connect rather.