Temporary Files Are Never Deleted

Advertisement

randallg
Donor
Joined:
Posts:
5

Temporary Files Are Never Deleted

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=&quot;ssh-rsa 2048 ***=&quot; -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=&quot;binary&quot; -filemask=&quot;*.*&quot;  -- &quot;sedar/*&quot; &quot;\\vi1\sedarin\incoming\&quot;" 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.

Capture.PNG

Reply with quote

Advertisement

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

Re: Temporary Files Are Never Deleted

Those files are automatically deleted normally, if you dispose your Session correctly. Please check.
If you still have the problem, please post debug log file (Session.DebugLogPath).

Reply with quote

randallg
Donor
Joined:
Posts:
5

Re: Temporary Files Are Never Deleted

That made the difference. I followed the C# example here assuming that leaving the using would take care of it, however my session variable is global, so it didn't.

using (session = open()) {
   int res = command();
   session.Close();
   return res;
}

Reply with quote

martin
Site Admin
martin avatar

Re: Temporary Files Are Never Deleted

It does not matter what is the scope of the session. The using will still call Dispose. Though there are no "global" variables in C#, so I'm not sure what exactly do you mean.

Reply with quote

Advertisement

You can post new topics in this forum