Posh-SSH icon indicating copy to clipboard operation
Posh-SSH copied to clipboard

Move-SFTPItem missing a -force parameter

Open ChrisRe-Lal opened this issue 2 years ago • 0 comments

Hello,

When moving an item between folder if the file name already exist in the destination we get an error.

[DBG]: PS C:\SCRIPT>> Move-SFTPItem -SessionId $SSHSesstion.SessionId -Path "./$($_.Name)" -Destination "./PDF/$($_.Name)"
Exception calling "MoveTo" with "1" argument(s): "Failed to rename file/home/[email protected]_UUID_106_5/fakt_20231029_50014114.p.202954.pdf M: Error during remote request handle."
At C:\Program Files\WindowsPowerShell\Modules\Posh-SSH\3.1.1\Posh-SSH.psm1:1393 char:17
+                 $itemInfo.MoveTo($Destination)
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SftpPathNotFoundException

Having a -Force option which would allow to automatically replace the file in the destination would be a great addition.

Chris

ChrisRe-Lal avatar Nov 03 '23 10:11 ChrisRe-Lal