Hi,

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

asked 01 Jun '10, 04:03

Christian's gravatar image

Christian
161
accept rate: 0%


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

Sftp sftp = new Sftp();
sftp.Connect(...);
sftp.Login(...);

// 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).

link

answered 01 Jun '10, 08:55

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.2k18
accept rate: 32%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×115
×1
×1
×1

Asked: 01 Jun '10, 04:03

Seen: 1,203 times

Last updated: 22 Mar '11, 23:22