Topic "Problem with time in FTP from UNIX"

Author Message
wolftxusa
[View user's profile]

Joined: 2016-01-08
Posts: 6
Location: Houston, TX, USA
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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
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.
wolftxusa
[View user's profile]

Joined: 2016-01-08
Posts: 6
Location: Houston, TX, USA
Dear Mr. Prikryl:
Thank you for your tip, it worked.

Code:
$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
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License