Get-SCPFile not clearing old file on overwrite
When overwriting a local file, and the downloaded file is shorter, Get-SCPFile does not remove the old file first.
As a result, the new file file contains the end of the old file. Eg if the old file is "abcdefghijk" and you download "www", you end up with "wwwdefghijk"
The command I was using was: Get-SCPFile -ComputerName $sddcMgr -Credential $cred -LocalFile '.\Cache\markerfile' -RemoteFile '/home/vcf/markerFile' -force
This was on the SDDC manager markerFile on VCF 4.2.
Thanks for reporting it. This is a big one I will have to figure out how to do it safely .
I think this is underlying library bug
This is how it is done on .Net (see Remarks)
https://docs.microsoft.com/en-us/dotnet/api/system.io.file.openwrite
so it can be fixed at
- script level
- posh-ssh level
- renci.ssh level
Since the solution might introduce security / access issues, I vote for 1 :)
but you can try to open issue to fix renci - it just need output.SetLength(0) after output = fileInfo.OpenWrite()
It is, thinking if I should post it to the library and wait for a fix which could be months to years or just download to a temp file, if successful, delete and copy.
the temporary file is a potential security issue that I mentioned above. the temporary path can have other owner/ACL, it can fill the available space, and so on... May be truncating be better, it mimic original scp
Beta 3 for 3.0 pushed to the gallery, if the file exists with get-scpitem it will error, if force is given it will delete and then download if it exists