Let me preface my question by saying that I don't need to use cp I was just trying cp to diagnose a deeper issue related to file creation during another process.
So when I ssh from Windows to a Linux server and try cp from the command line the first attempt fails with the error "cannot create regular file ... : Operation not permitted". The result of this is that it creates the file I am copying but leaves it empty. When I run the command again, leaving the existing empty file from the first attempt, I don't get an error and it copies the contents of the file to the existing file. I get the same result if I create the empty file in Windows and then use cp in ssh. This is writing a file to a shared network folder formatted with NTFS.
So my problem is that it doesn't seem to be able to create the file and write to it in the same operation, but if it creates the file first or it already exists it is then able to overwrite it.
The process I am trying to debug creates temp files with random names so I can't anticipate the file names and create empty ones ahead of the process. The result is a failed process with empty temp files. Any thoughts on where to look for the problem behind this issue?
Edit: When I cp the same file to a local temp directory it succeeds in creating and writing the file into the temp directory. The resulting file seems to have the same file permissions as the network version that fails.
Edit: In reply to user68186
Q Which version Ubuntu are you using? Looks like it's not Ubuntu so I guess I'm in the wrong place. It's Oracle Linux Server v8.4.
Q Do you ssh as a normal user, an admin user, or root? I believe it is as a normal user.
Q What is the ownership and permissions for the folder where you are trying to copy the file? drwxrwxr-x. 2 1073 1140 3 Jul 2 08:21