ftp_connect() & ftp_mdtime()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pesale86
Forum Newbie
Posts: 1
Joined: Mon Nov 24, 2008 1:17 am

ftp_connect() & ftp_mdtime()

Post by pesale86 »

Hi everyone! I'm trying to check time modification time for file stored on remote computer. I tried using ftp connection to do it, but it seems not work as I expected.

Code: Select all

<?php
 
    $filename = "/path/to/file";
 
    // Connect and login to ftp server
    $Connection = ftp_connect(ftp_server_IP_ addres) or die("Could not connect!");
 
    ftp_login($Connection,"user","pass");
    
    // Get time file was last modified
    $UNIXtime = ftp_mdtm($Connection, $filename);
    
    // Convert to human readable time
    if ($UNIXtime != -1) {
        $FILEtime = date("Y:m:d", $UNIXtime);
    }
    else echo "Error!";
    
    // Close ftp connection
    ftp_close($Connection);
 
?>
This code deny to connect to server (although some ftp clients connects to it with no problems). So, I realized something wrong with my server, because I connected to public server with no problems (public server IP addres: 194.159.255.135, file example: /pub/adware/win9x/ukphone2.txt, NO LOGIN). But, ftp_mdtime() returns -1 for every single file I tried.

I do not expect to help me with my server problem, but if someone have idea, please share it with me . But, what I realy need to know: What is wrong with ftp_mdtime()?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: ftp_connect() & ftp_mdtime()

Post by requinix »

There's nothing wrong with the function, only with your understanding of it or how your code uses it.

MDTM isn't supported on all FTP servers; check that yours has it. Otherwise try removing the leading slash (unlikely, but possible).
Post Reply