0 votes
by (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
by (148k 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");
}
by
When I try
ftp.Settings.RestoreDateTime = devFile.LastWriteTime;
compilator throw this:
Cannot implicitly convert type 'System.DateTime' to 'Rebex.IO.ItemDateTimes'
by (148k 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.
...