PutFileToDirectory Gives Wrong Error Message

Advertisement

aksarben
Joined:
Posts:
72

PutFileToDirectory Gives Wrong Error Message

When I call PutFileToDirectory to a server directory that does not exist, it correctly throws an exception. However, the error message is incorrect. Here's the code:
$fullFileName = $file.fullName
if ((Test-Path -path $fullFileName -pathType leaf) -eq $false) {
   throw "File $fullFileName does not exist"
}
$directory = Get-PathBelowRoot -clientRoot $clientRoot -file $file
$remove = $false
$session.PutFileToDirectory($fullFileName, $directory, $remove, $options)
The directory (bib) does not exist on the server, so an exception thrown, as expected.
Here's the output:
Sending file 'C:\Users\Dick\Documents\tch\ssh\client\bib\bibliography.htm'
Write-Error: Exception calling "PutFileToDirectory" with "4" argument(s): "Cannot create remote file '/C:/Users/Dick/bib/bibliography.htm'.
No such file or directory.
Error code: 2 Error message from server: No such file"
The message clearly says I'm trying to create a server file called
/C:/Users/Dick/bib/bibliography.htm. But that's the client file being sent, not
the name of the server file which will be written.

The error message should read:
Write-Error: Exception calling "PutFileToDirectory" with "4" argument(s): "Cannot create remote file '/bib/bibliography.htm'. No such file or directory.
Error code: 2 Error message from server: No such file"
The server is OpenSSH Server. Is this error message coming from the server? If not, is it something you can fix?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,506
Location:
Prague, Czechia

Re: PutFileToDirectory Gives Wrong Error Message

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,506
Location:
Prague, Czechia

Re: PutFileToDirectory Gives Wrong Error Message

When I try:
$session.PutFileToDirectory("C:\existing\test.txt", "/non/existing")
I get:
Exception calling "PutFileToDirectory" with "2" argument(s): "Cannot create remote file '/non/existing/test.txt'.
No such file or directory.
Error code: 2
Error message from server: No such file"
So it behaves as expected. Please double check the paths you are passing to Session.PutFileToDirectory.

Reply with quote

Advertisement

You can post new topics in this forum