Can’t Open Log File (Problem Solved)
See solution at end ▼
I get this error message when calling
I don’t understand what the error message means when it says logging has “been turned off.” I couldn’t find a switch to turn logging on or off. I assumed logging was enabled when I provided a log path (which I did).
Thinking perhaps I had to enable logging thru the WinSCP GUI, I logged on there & set the log path to the same value as I did in the code. Then this dialog opened, with the same error message text as I got in the PowerShell code.
<invalid hyperlink removed by admin>
I created the folder a few minutes before running the script. There's nothing unusual about the folder, and my account and “ALL APPLICATION PACKAGES” have “Full Control” permissions on the folder, but I still get the error. I even launched WinSCP so it was running when the script called
So, right now, I'm dead in the water. How do I get past this?
SOLUTION:
Originally, my
Recommend the following changes so future users can avoid this problem.
I get this error message when calling
Session.open()
:
I see other forum posts on error code 5, but none seem to apply to my scenario.Write-Error: Exception calling "Open" with "1" argument(s): "Error occurred during logging. It's been turned off.
Can't open log file 'C:\Users\Dick\Documents\PowerShell\Logs'.
System Error. Code: 5.
Access is denied"
I don’t understand what the error message means when it says logging has “been turned off.” I couldn’t find a switch to turn logging on or off. I assumed logging was enabled when I provided a log path (which I did).
Thinking perhaps I had to enable logging thru the WinSCP GUI, I logged on there & set the log path to the same value as I did in the code. Then this dialog opened, with the same error message text as I got in the PowerShell code.
<invalid hyperlink removed by admin>
SessionLogPath
is set to "C:\Users\Dick\Documents\PowerShell\Logs"
. Curiously, the error message refers to this path as a “file”. Is it confusing a folder with a file?
I created the folder a few minutes before running the script. There's nothing unusual about the folder, and my account and “ALL APPLICATION PACKAGES” have “Full Control” permissions on the folder, but I still get the error. I even launched WinSCP so it was running when the script called
Session.open()
, but still get a fatal error with the "Access is denied" message.
So, right now, I'm dead in the water. How do I get past this?
SOLUTION:
Originally, my
SessionLogPath
pointed to the folder where I wanted log files stored, per the documentation, which says SessionLogPath
is the “Path to store session log file to.” However, what WinSCP really needed was the path plus a log file name.
Recommend the following changes so future users can avoid this problem.
- Change description of
SessionLogPath
in documentation to Full path to session log, including file name at the end.
- Change the error message as follows:
a. Remove the phrases “Access denied” and “It’s been turned off.” These have nothing to do with the cause of the problem.
b. If the user-providedSessionLogPath
ends in a folder name instead of a file name, change message to SessionLogPath ends in a folder name. Please append a file name at the end of the path.
- Change property name to
SessionLogFile
. The nameSessionLogPath
can be kept for backward compatibility, but should be deprecated. Users should be alerted of the deprecation if they use theSessionLogPath
name.