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

MethodInvocationException,Set-SFTPContent

Open Satya318 opened this issue 5 years ago • 4 comments

Executed this cmd: Set-SFTPContent -SFTPSession $ThisSession -Path "C:/Users/satya/satya.txt" -Value "testData" the file does not exist in the dir "C:/Users/satya/". It has to create a new file with the name "satya.txt" . Getting below exception though file gets created at the specified dir.

Set-SFTPContent : Failed to write content to file C:/Users/satya/satya.txt
At line:1 char:1
+ Set-SFTPContent -SFTPSession $ThisSession -Path "C:/Users/satya/sat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], MethodInvocatio
   nException
    + FullyQualifiedErrorId : System.Management.Automation.MethodInvocationExc
   eption,Set-SFTPContent

Satya318 avatar Feb 17 '21 12:02 Satya318

Did you create the file first with new-sftpitem? 

darkoperator avatar Feb 17 '21 12:02 darkoperator

Did you create the file first with new-sftpitem?

No, but how the file gets created in the same specified dir ?

Satya318 avatar Feb 17 '21 12:02 Satya318

It does a writeall if not appended. Dont know how renci.ssh handles it in the library. It is raising a file not found error. Why does it raise the error and still create the file I dont know. Will add code to check for the file first and if -force is use create it sometime this week or next

Sent from my iPhone

On Feb 17, 2021, at 8:22 AM, Satya318 [email protected] wrote:  Did you create the file first with new-sftpitem? No, but how the file gets created in the same specified dir ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

darkoperator avatar Feb 17 '21 12:02 darkoperator

Found the culprit . Get-SFTPLocation -SFTPSession $ThisSession O/P : /C:/Users/satya why it returns one extra slash before C: even it is a windows machine.

I was trying with -Path "C:/Users/satya"

Satya318 avatar Feb 17 '21 12:02 Satya318