darkoperator / darkoperator/Posh-SSH
Get-SCPItem overwrites bytes in local file instead of replacing the entire file
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 1.1k
- Forks
- 222
- PR merge metrics
- No merged PRs in 30d
Description
When I use Get-SCPItem and overwrite a local file I expect the local file to be completely overwritten. What I'm finding is that the bytes are written to the existing file starting at offset 0. This can be reproduce by running Get-SCPItem to retrieve a file which is smaller in size then the local file it will overwrite.
Ubuntu-18.04-x64 can be used for the remote and host machine to reproduce. I have seen this issue using different remote machines. Edit: I can confirm this happens using Windows 10 as the host machine too.
- On remote machine make a file
echo "abcdef" > a.txt - On remote machine make another file
echo "def" > b.txt - On local machine run
Get-SCPItem -Path "/root/a.txt" -Destination "./" -Computer localhost -Port 10022 -Force -PathType File - On local machine run
more a.txt, note output should beabcdef - On local machine run
Get-SCPItem -Path "/root/b.txt" -Destination "./" -Computer localhost -Port 10022 -Force -PathType File -NewName a.txt - On local machine run
more a.txt
At this point I would expect the local file named a.txt to contain def but instead it contains def\nef.
The use of -NewName parameter has no bearing on the issue. The remote file named a.txt can be modified in between the calls to Get-SCPItem to reproduce the issue.

Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Get-SCPItem implementation and the code that writes downloaded content to an existing local destination. Reproduce the issue with the two remote files and the commands given, then verify that replacing a larger file leaves only the downloaded file's bytes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100