py-winrm-plugin icon indicating copy to clipboard operation
py-winrm-plugin copied to clipboard

WinRM file copier appends to an existing destination file when "Override?" is off

Open skywalkw3r opened this issue 1 month ago • 0 comments

CopyFiles.winrm_upload() in contents/winrm-filecopier.py sends the file in base64 chunks with add-content ... -encoding byte. It only removes an existing destination when the override option is enabled. With override off (the default), every chunk is appended to whatever is already at the destination.

Steps to reproduce

  1. Configure a Windows node to use the WinRM Python file copier, leaving "Override?" unchecked.
  2. Create a job with a Copy File step that copies a local file (e.g. a file containing hello world) to C:\temp\file.txt.
  3. Run the job twice.

Actual

Both runs succeed. After the second run, C:\temp\file.txt contains the content twice (hello worldhello world). For binary files the result is corrupt. Nothing in the job output says anything went wrong.

Expected

The option is described as "Overrides the file on the remote server if it already exists", so with it off the existing file should not be changed. The second run should fail with a clear message (or at least leave the file alone), not quietly produce a corrupted file.

I reproduced it with a fake WinRM session that simulates add-content, and on a local Rundeck 6.4.0-SNAPSHOT server against a stub WinRM endpoint: both runs succeeded and the file held the content twice. I have not run it on a real Windows node, but the PowerShell commands the copier sends do the same thing there.

skywalkw3r avatar Oct 18 '26 20:10 skywalkw3r