Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
4.6k views
in .NET FTP by
Hi there,
The ModTime() method (with the comments I added) is as follows:
public virtual DateTime ModTime(string remoteFile)
{
CheckConnection(true);

FTPReply reply = control.SendCommand("MDTM " + remoteFile);
lastValidReply = control.ValidateReply(reply, "213");

// parse the reply string ...
DateTime ts = DateTime.ParseExact(lastValidReply.ReplyText, tsFormat, CultureInfo.CurrentCulture.DateTimeFormat);

///The above DateTime variable 'ts' has the UTC time, but the program
///converts it to UTC once again and returns, which thus produces
///incorrec time.
return ts.ToUniversalTime();

///So ,
///Return the ts because it is in UTC format. No need to convert into UTC
///onceagain.
return ts;
}

Am I correct!!!! ,,it works like that, atleast for the ftp sites to which I connect.
I would appreciate if you could agree or disagree with me :)

Thank you,
Srinivas Varukala

2 Answers

0 votes
by
I get the same results. However if you use the dirdetails function the correct time gets returned.
0 votes
by (161k points)
DirDetails will return the timestamp at the server end - which may well be in a completely different time zone to the client.

I think the first poster has a point - as the time returned by ModTime() is already UTC, calling ToUniversalTime() will return the wrong result.

What we really want is to retrieve the time (which is in UTC) and convert it to the local time, so we are changing the code to:

// get the timestamp, it is in UTC
DateTime ts =  
    DateTime.ParseExact(lastValidReply.ReplyText, tsFormat, null);
            
 // return the equivalent in local time
return TimeZone.ToLocalTime(ts);

Categories

...