Ftp_rawlist does not show last modified date in uniform format

Hello experts, I am new to php so have been struggling with a simple code of ftp_raw_list My code is:

$ftp_server = "xxxx";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
$mode = ftp_pasv($ftp_conn, TRUE);
$ftp_rawlist = ftp_rawlist($ftp_conn, ".");

Here I observe that last modified date of the files are NOT is same format. Here is a sample:

  16 => string '-rw-r--r--    1 807      801          7597 Apr 01  2019 year_available.pdf' (length=74)
  19 => string '-rw-r--r--    1 807      801          8250 Sep 03 17:27 year_missing1.pdf' (length=75)
  20 => string '-rw-r--r--    1 807      801         24208 Jan 02 12:14 year_missing2.pdf' (length=75)
  21 => string '-rw-r--r--    1 807      801          6849 Feb 04 14:12 year_missing3.pdf' (length=75)
  22 => string '-rw-r--r--    1 807      801          6778 Jul 04  2019 year_again_showing1.pdf' (length=75)
  23 => string '-rw-r--r--    1 807      801          8668 Nov 01 09:17 year_missing4.pdf' (length=75)
  24 => string '-rw-r--r--    1 807      801          7065 Oct 04 11:46 year_missing5.pdf' (length=75)

My task is to show ftp file list in a tabular form with an option of dynamic sorting - file name wise, date wise, size wise etc. Rest I could do , but I am not able to sort the files in date column because of non-uniformity of date structure. Please guide me how do I format the dates in a uniform manner let us say yyyy-mm-dd hh24:mi so as to successfully sort on date field?

So how do you know the year? Is it just skipped for the current year? Looks like the DateTime class can handle it like that

var_dump((new Datetime('Feb 04 14:12'))->modify('+1 day'));
// "2020-02-05 14:12:00"

No , year part is being randomly skipped for previous year’s files too. File shown in slno 19 is of year 2019, 20 is of year 2020.

what’s slno? if you don’t get the year, you won’t be able to sort it.

By slno mean, I was referring to the example given above. When I browse the same ftp directory over web, it shows full date format in all the files. Ex.
|SRTS003_201901.pdf|6.3 kb|Fri, 01 Feb 2019 09:57:00 GMT||—|---|—|
| SRTS003_201902.pdf|8.8 kb|Fri, 01 Mar 2019 03:54:02 GMT|
| SRTS003_201903.pdf|7.4 kb|Mon, 01 Apr 2019 11:31:00 GMT|
| SRTS003_201904.pdf|6.6 kb|Wed, 01 May 2019 04:11:20 GMT|
| SRTS003_201905.pdf|9.1 kb|Sat, 01 Jun 2019 11:30:00 GMT|

strange, i would say the FTP server software is broken then. make a PHP script that returns all the data in JSON format to use as an API.

PS: looks like a configuration thing

maybe you could send a raw command


Sorry for replying late. I got the date format changed for my user too. I checked with ftp_raw command. No change. For files later than last 6 months it does not bring the year part , here the sorting fails. Pl help

so it’s not random? what’s the problem then? the year is 2020 for all files lower then current month/day, and 2019 for all files higher then current month/day.

Well Thank you chorn, I have now written a script to derive year by comparing with a 6 months old date.

Sponsor our Newsletter | Privacy Policy | Terms of Service