Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

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.
randallg

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;
}
martin

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).
randallg

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.