tags:

views:

360

answers:

2

I seem to be running into a documentation drought with CURL vs FTP, can anyone tell me how to get the last modified date of a given file using PHP / CURL.

Many thanks!

+1  A: 

If you don't have to use curl, have a look at php's ftp_mdtm. It "returns the last modified time of the given file".

middus
Thanks for your reply, I would prefer to be able to stick with CURL as that is what I will be using to download the file if various conditions are meat. I don't fancy having more than one FTP connection going if I can get away with it.
ILMV
Well, I'm building a proof of concept at the moment, and the PHP FTP functions didn't do to well in my earlier research. I will implement a non-curl test and see how I get on. :)
ILMV
+3  A: 

Try this, it seems to work ok here but I have only tested it on one server:

<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"ftp://server/file");

curl_setopt($curl, CURLOPT_USERPWD, "user:pass");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_NOBODY, 1);

curl_setopt($curl, CURLOPT_FILETIME, TRUE );

$result = curl_exec ($curl);
$time = curl_getinfo($curl, CURLINFO_FILETIME);
print date('d/m/y H:i:s', $time);

curl_close ($curl);
Tom Haigh
Many thanks for your reply! I've decided to build both proof of concepts, I'll let you know how I get on.
ILMV