Jump to content

ftp_connect() & ftp_mdtime()


pesale86

Recommended Posts

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.

 

<?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()?

Link to comment
Share on other sites

This works fine for me:

 

<?
    $filename = "/pub/adware/win9x/ukphone2.txt";

    // Connect and login to ftp server
    $Connection = ftp_connect('194.159.255.135') or die("Could not connect!");

    ftp_login($Connection,"ftp","me@here.com");

    // 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);
        print "Modification time: $FILEtime\n";
    }
    else echo "Error!";

    // Close ftp connection
    ftp_close($Connection);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.