Post a reply

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)


Topic review


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.

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();
   return res;

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

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.
TARGETSITE: Void Open(WinSCP.SessionOptions)
   at WinSCP.Session.Open(SessionOptions sessionOptions)

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="" 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 name="pwd" start="2023-03-10T19:00:35.986Z">
      <cwd value="/stockwatch.sftp" />
      <result success="true" />
  <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">

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.