FTP File DateTimes are wrong

0 votes
asked Aug 11, 2014 by Ftp (300 points)
edited Sep 5, 2014

Hello,

In Rebex, the FTP files LastModified and LastWrite DateTime are displaying the same like "31-Aug-2014 17:16:00" for a file called "CCDATA.txt".

But the same file modified date is displaying as "08-Aug-2014 14:30:00" in FileZilla.

Client is telling that FileZilla is correct. But through Rebex we are displaying other date which Rebex has provided.

Which one is correct, we are unable to find the solution. Because the difference is not in minutes or hours. The difference is more than 7 days.

Please help me to get the correct date times of the FTP files.

Regards, Naga Suresh D

Applies to: Rebex FTP/SSL

2 Answers

+1 vote
answered Aug 12, 2014 by Tomas Knopp (58,890 points)
edited Aug 21, 2014

Hello,

this is strange as Rebex FTP component displays the dates as reported by the FTP server. Would it be possible to run the following code snippet against your server :

        Ftp ftp = new Ftp();
        ftp.Connect("ftpServer");
        ftp.Login("user", "password");

        ftp.ChangeDirectory("dirWith_CCDATA.txt"); // change to the directory which contains the problematic CCDATA.txt file

        Console.WriteLine(string.Join("\n", ftp.GetRawList(null, FtpListingType.List)));

        Console.WriteLine("\n\n");
        Console.WriteLine(string.Join("\n", ftp.GetRawList(null, FtpListingType.MachineProcessingList)));
        ftp.Disconnect();

and then please send us the output. It will enable us to tell what is actually going on.

commented Aug 12, 2014 by Ftp (300 points)
edited Aug 12, 2014

Hello,

I have executed the same code which you have given.

The below line is displaying the same date as displayed earlier (i.e; Incorrect Date). Console.WriteLine(string.Join("\n", ftp.GetRawList(null, FtpListingType.List)));

But MachineProcessingList method is not executing. It is throwing the below exception

"Syntax error, command unrecognized. This may include errors such as command line too long (500)."

Thanks Naga Suresh D

commented Aug 13, 2014 by Tomas Knopp (58,890 points)
edited Aug 13, 2014

Hello,

thank you for your response. The GetRawList method returns info about the files which the FTP server announces and Rebex does not modify the returned dates in any way so it looks like the problem might be somewhere else.

To be able to further look into this issue we would need a log from the FileZilla client as well as log from the Rebex FTP. So if you send those two to us we will be able to compare them and hopefully see why FileZilla and Rebex get different date results.

commented Aug 18, 2014 by Ftp (300 points)
edited Aug 18, 2014

Hello,

You can find the FTP log files in the below OneDrive links.

FileZilla Ftp Log http://1drv.ms/1pzt0vT

Rebex Ftp Log http://1drv.ms/1pztuSJ

Please help me to resolve the file date time issue in FTP.

commented Aug 18, 2014 by Tomas Knopp (58,890 points)
edited Aug 18, 2014

Thank you for log files. One more request from me - could you please try to run the following code snippet against the FTP server and let us know the console result of it:

Ftp ftp = new Ftp();

ftp.Connect("tf.ftp.citonline.com");
ftp.Login("user", "password");

ftp.ChangeDirectory("upload_directory");
Console.WriteLine("client time: {0}", DateTime.Now);

string remotePath = "rebextest.txt";
ftp.PutFile(new MemoryStream(), remotePath);

DateTime remoteDateTime = ftp.GetFileDateTime(remotePath);
Console.WriteLine("server time: {0}", remoteDateTime);

ftp.Disconnect();
commented Aug 20, 2014 by Ftp (300 points)
edited Aug 20, 2014

Hello,

Here in the above code you have given the "PutFile" method. But I don't have a permission to upload the file into this FTP. I have permission to only for downloading.

Thanks Naga Suresh D

commented Aug 20, 2014 by Tomas Knopp (58,890 points)
edited Aug 20, 2014

Thank you for your reply. From the FileZilla log I can see that it uses MDTM command to get the correct DateTime of the remote file.

Please try the following snippet to get the right date time via Rebex using the MDTM command and let us know if it works correctly now:

Ftp client = new Ftp();
// connect and login

client.Settings.ForceMdtmForGetFileDateTime = true;

var dt = client.GetFileDateTime("OUTBOX/CCDATA.TXT");
Console.WriteLine(dt);
client.Disconnect();
commented Aug 21, 2014 by Ftp (300 points)
edited Aug 21, 2014

Thanks for your reply.

I executed above code. Now Rebex is displaying a different date (Near to FileZilla). But not exact the FileZilla's date.

Below I have given the date and times for the same file in different scenarios.

Rebex - WithOut using the above code : 31-July-2014 05:16:00 PM Rebex - Using the above code : 20-Aug-2014 08:01:22 PM FileZilla : 21-Aug-2014 01:31:00 AM


I am too confusing regarding the date and time information.

Can you please help me that, which one is correct?

0 votes
answered Aug 21, 2014 by Tomas Knopp (58,890 points)
edited Sep 5, 2014

Hello,

from the FileZilla log it also looks like it is applicating some kind of time offset to the date and time returned by the MDTM command which results in the -5hours 30minutes time difference between FileZilla and Rebex FTP clients. I have downloaded the FileZilla client and found a way to change the displayed remote date time by setting the server time zone offset.

Could you please look into your FileZilla client if there is any time offset set for the problematice FTP site? You can check it under:

File / Site Manager / select FTP site / Advanced tab / Adjust server time zone offset:

Setting the Filezilla offset to 0hours 0minutes should I guess yield the same date time results as this Rebex code:

Ftp client = new Ftp();
// connect and login

client.Settings.ForceMdtmForGetFileDateTime = true;

var dt = client.GetFileDateTime("OUTBOX/CCDATA.TXT");
Console.WriteLine(dt);
client.Disconnect();

Could you please confirm?

P.S. Regarding the difference between the time which your FTP server returns for the LIST and MDTM commands you should contact the server vendor and ask them why different dates are returned for these two commands.

commented Aug 22, 2014 by Ftp (300 points)
edited Aug 22, 2014

Thanks for your reply.

I verified 'Adjust server time zone offset' in FileZilla to this FTP server. it displays as 0 Hours, 0 Minutes.

Still FileZilla is displaying the file date time 5.30 hrs more than Rebex.

What should I do. Please suggest?

commented Aug 22, 2014 by Lukas Pokorny (112,470 points)
edited Aug 22, 2014

Hello, where are you located? 5:30 is the difference between UTC Time Zone (UTC+00:00) and India Time Zone (UTC+05:30). If you happen to be in India, try converting the DateTime returned by GetFileDateTime to local time:
var dt = client.GetFileDateTime("OUTBOX/CCDATA.TXT").ToLocalTime();

commented Aug 22, 2014 by Ftp (300 points)
edited Aug 22, 2014

After executing the above code, Now I was able to get the correct date time which FileZilla is displaying.

But in Rebex the time is displaying more one second than FileZilla.

Other than this (one second) everything is fine.

commented Aug 22, 2014 by Lukas Pokorny (112,470 points)
edited Aug 22, 2014

Well, in that case, look into the log, check out the response to MDTM command (used by Rebex FTP's GetFileDateTime) and check its last two digits - do they match the seconds in the retrieved date/time value? If they don't match in Rebex FTP, please report this to us. If they don't match in FileZilla, please report it to them :-)

commented Aug 22, 2014 by Ftp (300 points)
edited Aug 22, 2014

Yes. I observed that, Rebex is correct. FileZilla only displaying the one second extra.

Thank you so much for your help.

commented Aug 22, 2014 by Ftp (300 points)
edited Aug 22, 2014

Is there any harm to use the below line of code by default ?

client.Settings.ForceMdtmForGetFileDateTime = true;

commented Aug 22, 2014 by Lukas Pokorny (112,470 points)
edited Aug 22, 2014

By default, GetFileDateTime method uses MLST command if the server supports it and MDTM if it doesn't. Unlike MDTM, MLST always reports time in UTC time zone, which is converted to local time by the method. On the other hand, MDTM returns date time in UTC time zone on some FTP servers and in local time zone on others. So MLST is usually a better choice. However, your server doesn't support MLST, so the line has no effect. This means that there is actually no reason to keep it, but keeping it won't do any harm. But if you start using a different FTP server, make sure it works as expected.

commented Aug 22, 2014 by Ftp (300 points)
edited Aug 22, 2014

Ok. Thank you.

commented Sep 5, 2014 by Ftp (300 points)
edited Sep 5, 2014

In some FTPs we are getting exception ("Subcommand MDTM not valid (500).") while calling the below line of code to get LocalDateTime of the FTP files. client.GetFileDateTime(item.Path).ToLocalTime();

commented Sep 5, 2014 by Lukas Pokorny (112,470 points)
edited Sep 5, 2014

This is known to occur on some IBM AS/400 (iSeries) servers - it looks like they don't support the MDTM command (or at are not configured to support it), which means GetFileDateTime method does not work on them. As a workarond, call GetList() method in the item's parent folder and retrieve the DateTime from the listing.

...