download a file from ftp using curl and php -
I am trying to download a file from an FTP server using curl and php but for any help me Can not find the document
$ curl = curl_init (); Curl_setopt ($ curl, CURLOPT_URL, "ftp: // $ _ FTP [server]"); Curl_setopt ($ curl, CURLOPT_FTPLISTONLY, 1); Curl_setopt ($ curl, CURLOPT_USERPWD, "$ _FTP [username]: $ _ FTP [password]"); Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); $ Result = curl_xax ($ curl);
I can get a list of files but about
My guess is that your URL is pointing to a directory and not the file you need to have the full URL CURLOPT_URL feed in the file. In addition, if you want to download a file, you would like to save it from anywhere.
For example:
$ curl = curl_init (); $ File = fopen ("ls-lR.gz", 'w'); Curl_setopt ($ curl, CURLOPT_URL, "ftp://ftp.sunet.se/ls-lR.gz"); #input curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); Curl_setopt ($ curl, CURLOPT_FILE, $ file); #out put curl_setopt ($ curl, CURLOPT_USERPWD, "$ _FTP [username]: $ _ FTP [password]"); Curl_exec ($ curl); Curl_close ($ curl); Fclose ($ file);
Comments
Post a Comment