Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get modified date via FTP using PHP / CURL

Tags:

php

curl

ftp

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!

like image 867
Ben Everard Avatar asked Mar 17 '10 12:03

Ben Everard


1 Answers

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);
like image 163
Tom Haigh Avatar answered Oct 06 '22 00:10

Tom Haigh