fieldrndservices/libssh2-labview

SFTP - File Attributes - Modified Time and File Size

ngblume opened this issue · 6 comments

When establishing a SFTP connection, followed by opening an SFTP file attribut reference and querying "modified time" and "file size", erratic numbers are returned, even sometimes including "0".
Edit: somehow now it only gives me zeroes..

It appears as if it takes the data from a specific adress in memory, without that adresses actually containing the correct data.
When using the identical credentials and file path with SCP, everything runs smoothly.

image

@ngblume This is not necessarily a bug with the implementation, but perhaps a bug in documentation and lacking examples.

The SFTP Attributes:Create.vi creates an empty struct within the libssh2lv C library. This is unpopulated with actual, meaningful data about a file. The SFTP File:Read Status.vi must be used to populate the empty Attributes struct. Structs are like clusters in LabVIEW. Before the SFTP File:Read Status.vi is called, the SFTP Attributes can be whatever the libssh2 C library decided to use during struct initialization. It appears random values are used.

The following VI snippet should work, or at least be useful as a template to read the attributes of a file through the SFTP API:

SFTPFile_Attributes_Example

If you have the source code and Caraya Unit Test package installed, then the Tests.lvlib:SFTP File.lvlib:Read Status.vi test might be useful since a more complete, "official" example is not currently available.

Hmm, looking at the SFTP examples, specifically Simple SFTP File Download, it appears I made the same mistake and did not call the Read Status.vi before reading the attributes. I am in the process of fixing this example.

I have updated the Simple SFTP File Download example to use the Read Status.vi as of ff8facd. I will hold off on creating a new release until I get confirmation this has been resolved.

@volks73 That's exactly the example I based my code on.

I think for the Simple SFTP File Download.vi it makes even more sense to use the "Read Size.vi", since it contains all necessary steps and this should be a simple example with very little risk of errors..
image

I changed my code and it works properly now...
Except the timestamp is weird..
The context help says UNIX epoch, which for me means directly convertable in LabVIEW...
But that's not what I'm seeing...
The file was changed yesterday..
Somehow it is off by 66 years...
image
image

@ngblume Ha! I forgot about the Read Size.vi. I have a vague memory of adding that VI because reading the file size is such a common need and the lower level SFTP Attributes API is a little cumbersome. I have changed the example to use the simpler Read Size.vi as of 30b943e.

I believe it is a UNIX timestamp, which uses 1970 as the epoch year, but LabVIEW on Windows (not sure about macOS or Linux) uses 1904 as the epoch year. I thought a UNIX timestamp was directly convertable as well, but maybe I was thinking of a UTC timestamp.

Fixed that offset in my code
Seems fixed for me...
New release could be created...
Thanks !