Problem with time in FTP from UNIX

Advertisement

wolftxusa
Joined:
Posts:
7
Location:
Houston, TX, USA

Problem with time in FTP from UNIX

Dear all:
I use command line WinSCP and issue a directory listing to a UNIX (or UNIX-like) FTP server via the method Session.ListDirectory. I get back a list of files with names and sizes, but the LastWriteTime is always 12:00:00 AM (midnight) even though the date is right. When I do a GET, the file has the same date as the DIR listing, but the time is now correct, for example 1:15 PM. I want to compare whether a file has been updated, so the time can be critical within a date. BTW, the date in my example was 12/10/2015, not even a month ago.

I use a workaround to extract and compare just the date, but I wonder whether anybody has encountered this before and knows a solution.

Possibly related to this, I noticed that a DIR listing gives me a 'Mode' attribute on a Windows server but 'FileType' on a UNIX-like server. Am I overlooking critical parameters to get what I want in the right format?

Oh, and I am new to this. Thanks for your patience.
Wolfgang

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Problem with time in FTP from UNIX

If the server supports old LIST listing command only, the time is typically not provided in the listing for old files (over a year old).

This is not a problem with modern MLSD command.

Try using Session.GetFileInfo. It should retrieve a full timestamp, if the server supports at least an MDTM command.

Reply with quote

wolftxusa
Joined:
Posts:
7
Location:
Houston, TX, USA

Dear Mr. Prikryl:
Thank you for your tip, it worked.

$lv_DateTime = $global:FTP.Session.GetFileInfo($lv_FullName).LastWriteTime
$ls_File.TimeStamp = $lv_DateTime
I have a record ls_File from the directory listing where everything but the TimeStamp (LastWriteTime) is correct. I simply added the call you suggested and replaced the TimeStamp with the result. It seems to work for other UNIX and Windows systems as well, so I don't have to differentiate. Great tip!

Regards,
Wolfgang

Reply with quote

Advertisement

You can post new topics in this forum