Modified date time changes when moving a file from Windows to UNIX server using SSH.NET

我们两清 提交于 2019-12-06 13:56:27

The timestamp of the file on the remote SFTP server will always be set to the the time the remote file was modified the last time (i.e. the upload time) - As with any other file on a Linux server.

As the question you have linked yourself says:

after uploading files, the creation- and modified dates are altered to the time when the upload took place.


I assume you somehow expect that the local file timestamp is involved. It's not. You are not uploading a local file. You are uploading data from a stream (Stream interface). SSH.NET (let only SFTP server) does not even know that your instance of Stream originated from a local file. So SSH.NET (let only the SFTP server) cannot know the local file timestamp.

In the end, it behaves like if you have copied a file on the Linux server via a pipe (similar to a stream) instead of using cp command, like:

cat source > target

The contents gets copied, but the timestamp will always be the time of the last modification (i.e. the copy time).


If you want the remote file timestamp to match timestamp of the source local file, you have to code that (like done in the question you know already):
SSH.NET: Is it possible to upload files using SFTP and preserve the file dates from source files?

Note that it's not true that "SSH.NET does it wrongly". It does what it should (could). It nowhere promises you to preserve the timestamp for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!