Hi,
I am trying to download a file with PHP from an FTP server which i can access from http too. For example: FTP://username:[email protected]/file_name_here.gz
. The file is forced as an attachment from the server (not as a PDF or TXT would do eg: output).
I tried it with 3 different methods:
- file_get_contents -> Return a zero size file
- Curl -> times out
- FTP function -> Returns a zero size file
I think CURL is the way to do it but I can't manage to download the file... Here is my code:
$curl = curl_init();
$url ='ftp://'.$network['username'].':'.$network['password'].'@'.$network['metadata_url'].'/'.$path.'/'.$data['title'];
curl_setopt($curl, CURLOPT_URL,$url);
//curl_setopt($curl, CURLOPT_USERPWD, "$_FTP[username]:$_FTP[password]");
//curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$file = fopen("./feeds/".$data['title'], "w");
curl_setopt($curl, CURLOPT_FILE, $file);
$result = curl_exec ($curl);
I tried both setting the username and password in the CURLOPT_URL and setting them with CURL. The same thing happens with both of the ways...
Can you help?
Edit
: Forgot to mention that the file is served from the server dynamically. So for example the real file is: filename.gz.check
which when i ommit the .check
part i get the original file. Dunno why they do this but I need to work with this as it is.