0

My application daily generates a file that is being sent to a remote host using SCP. The generated file may or may not be empty, and the file usually exists in the remote host (the one from the previous day). I have noticed that, when replacing an empty file (in the remote host) with an also empty file (being generated) using SCP, the timestamp of the remote file after a succesful scp DOES NOT CHANGE. This does not happen unless both files are empty (the one being sent and the one already there). SCP does not end with any error and in fact I can see the UPLOAD progress (even though it shows 0 bytes). Is there something I am missing about how scp works with empty file transmissions? Is there any way I can make SCP to change the timestamp of the remote file after a successful sending even if the file is empty?

1
  • 1
    Cannot reproduce. Several times I sent a file (empty or not) from Kubuntu via scp to Raspbian and overwrote the remote copy (empty or not). mtime and ctime were updated each time. Please edit the question and make clear: (1) what timestamp exactly? and how do you check it? (2) local side OS and the tool (including its version) you used; (3) remote side OS, filesystem and SSH server; (4) the exact command you used. Commented Mar 14, 2019 at 16:14

2 Answers 2

2

I have encountered a similar problem, and now I think the problem is not related with scp. As I reported at https://bugs.centos.org/view.php?id=16079, in my CentOS 6.9, overwriting a file in a NFS disk with an empty string does not update the file's modification timestamp (mtime). I think you can reproduce the same problem as follows:

printf 'hello\n' > hello.txt stat hello.txt sleep 5 printf '' > hello.txt stat hello.txt 

Therefore, I think you have to get a list of copied file names (This question How to get files list downloaded with scp -r seems relevant), and use touch command to them.

0

Try running scp with the -p option:

-p
Preserves modification times, access times, and modes from the original file.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.