Nancy
Nancy

Reputation: 504

ftp_mdtm function to get latest modified images based on date

I am downloading remote images from one server to another and that part I did good. Now I need to download only the newest modified images. Before I even get to that, I am trying to show modification time for all images using ftp_mdtm function. But I keep getting

was last modified on : January 01 1970 01:00:00

I googled and looked for the answer here, but everything I tried didn't help me. The entire code is here:

    <?php
    $ftp_server = "xxx.xxx.xxx.xxx";
    $ftp_user = "xxx";
    $ftp_pass = "xxx";
    $DIR="/xxx/";

    $conn = ftp_connect($ftp_server);
 if(!$conn) {
 exit("Can not connect to: $ftp_server\n");
 }

 if(!ftp_login($conn,$ftp_user,$ftp_pass)) {
 ftp_quit($conn);
 exit("Can not log on to\n");
 }

 ftp_chdir($conn,$DIR);

 $files = ftp_nlist($conn,'.');
//var_dump($files);
 for($i=0;$i<count($files);$i++) {

 if(!ftp_get($conn,$files[$i],$files[$i],FTP_BINARY )) {
 echo "Can not download {$files[$i]}\n";
 }
 else {echo "Success";
 $buff = ftp_mdtm($conn_id, $file);

if ($buff != -1) {

    echo "$file was last modified on : " . date("F d Y H:i:s.", $buff);
} else {
    echo "Couldn't get mdtime";
}
 }

 }


 ftp_quit($conn);
 ?>

Upvotes: 0

Views: 512

Answers (1)

Nancy
Nancy

Reputation: 504

UPDATE: Thanx to great question by @arkascha, I realized I made a mistake in my code. The $buff variable was defined in a wrong way. The correct way is as follows:

     $buff = ftp_mdtm($conn_id);

if ($buff != -1) {

    echo "$file was last modified on : " . date("F d Y H:i:s.");
       } else {
    echo "Couldn't get mdtime";
}

Upvotes: 1

Related Questions