SFTP GetFile - How to retain original date/time file when copy

0 votes
asked Dec 13, 2016 by davidffh (120 points)

Hi;

I'm evaluating Rebex SFTP for purchase, I'm downloading files and copy them in a folder but the files date/time is the current not the original in the sftp folder.

How can I retain the original date/file when copy files with GetFile i my windows folder?

Regards

Applies to: Rebex SFTP

1 Answer

0 votes
answered Dec 16, 2016 by Lukas Pokorny (99,970 points)

You can instruct Rebex SFTP to restore date/time using Sftp.Settings.RestoreDateTime property.

Sample code:

using (var sftp = new Sftp())
{
    sftp.Connect("test.rebex.net");
    sftp.Login("demo", "password");

    // restore last write time in subsequent operations
    sftp.Settings.RestoreDateTime = ItemDateTimes.LastWriteTime;

    // download the file
    sftp.GetFile("readme.txt", "readme.txt");
}
commented Mar 27 by robi16siv (100 points)
When I try
ftp.Settings.RestoreDateTime = devFile.LastWriteTime;
compilator throw this:
Cannot implicitly convert type 'System.DateTime' to 'Rebex.IO.ItemDateTimes'
commented Mar 27 by Lukas Pokorny (99,970 points)
Sftp.Settings.RestoreDateTime property does not specify a DateTime value. It's used to specify which of the date/time attributes of the file to restore to values retrieved from the server. To set the downloaded file's LastWriteTime to a custom value, just call System.IO.File.SetLastWriteTime("readme.txt", devFile.LastWriterTime) after the GetFile method completes.
...