darkoperator / darkoperator/Posh-SSH

Get-SCPItem overwrites bytes in local file instead of replacing the entire file

Open
#320 2 comments 0 reactions 0 assignees View on GitHub

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.

  1. On remote machine make a file echo "abcdef" > a.txt
  2. On remote machine make another file echo "def" > b.txt
  3. On local machine run Get-SCPItem -Path "/root/a.txt" -Destination "./" -Computer localhost -Port 10022 -Force -PathType File
  4. On local machine run more a.txt, note output should be abcdef
  5. On local machine run Get-SCPItem -Path "/root/b.txt" -Destination "./" -Computer localhost -Port 10022 -Force -PathType File -NewName a.txt
  6. 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.

image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.