Preserver Date Created Timestamp on SFTP transfers

0 votes
asked Jun 1, 2010 by Christian (120 points)
edited Mar 22, 2011


I would like to preserve the original creation date/time and modified date/time after a file has been transfered.

Is there a way of doing this? I know WinSCP offers this option, so I assume it is possible

Regards, Christian

Applies to: Rebex SFTP

1 Answer

0 votes
answered Jun 1, 2010 by Lukas Pokorny (110,970 points)
edited Jun 1, 2010

Yes, this is possible using the following code (C#):

Sftp sftp = new Sftp();

// upload the file
sftp.PutFile(localFile, remoteFile);

// assign creation and modification time attributes
SftpAttributes attributes = new SftpAttributes();
System.IO.FileInfo info = new System.IO.FileInfo(localFile);
attributes.Created = info.CreationTime;
attributes.Modified = info.LastWriteTime;

// set attributes of the uploaded file
sftp.SetAttributes(remoteFile, attributes);

(If you prefer VB.NET, please let me know.)

Please be aware that creation date/time will only be set if the SFTP server supports SFTP v4. On servers that only support SFTP v3 (such as OpenSSH), only modified date/time will be set (this is a limitation of SFTP v3).