I've been using WinSCPnet in a console program for some time to retrieve files from our sftp server in the cloud. Suddenly my program started having this exception:
20230310 03:38:23.199 UNHANDLED EXCEPTION: WinSCP process terminated with exit code 1. Error output was "Can't open log file 'C:\Users\Administrator\AppData\Local\Temp\wscp20D0.02BF8098.298.tmp'.
System Error. Code: 19.
The media is write protected
Error occurred during logging. Cannot continue.". Response log file C:\Users\Administrator\AppData\Local\Temp\wscp20D0.02BF8098.298.tmp was not created. This could indicate lack of write permissions to the log folder or problems starting WinSCP itself.
SOURCE: WinSCPnet
TARGETSITE: Void Open(WinSCP.SessionOptions)
STACKTRACE:
at WinSCP.Session.Open(SessionOptions sessionOptions)
at Stockwatch.Sftp.Sftp.open()
Upon further investigation it turned out that the temp directory had over 2 million files in it that contain things like this:
<?xml version="1.0" encoding="UTF-8"?>
<session xmlns="http://winscp.net/schema/session/1.0" name="***" start="2023-03-10T19:00:32.796Z">
<group name="open sftp://***.com -hostkey="ssh-rsa 2048 ***=" -privatekey=*** -timeout=15" start="2023-03-10T19:00:35.649Z">
</group>
<group name="pwd" start="2023-03-10T19:00:35.986Z">
<cwd>
<cwd value="/stockwatch.sftp" />
<result success="true" />
</cwd>
</group>
<group name="get -delete -nopermissions -preservetime -transfer="binary" -filemask="*.*" -- "sedar/*" "\\vi1\sedarin\incoming\"" start="2023-03-10T19:00:36.042Z">
</group>
Deleting the *.tmp files corrected the problem. It was not a permissions problem.
Is there any way to have these files automatically deleted?
These files continue to build up.