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


How to save the XML log

This VB code will close a WinSCP session, saving the XML log to xmlSavePath
Imports System.IO

Imports System.Reflection

Sub EndWinScpSession(ByVal ftpSession As WinSCP.Session, ByVal xmlSavePath As String)
        'Close the WinSCP session, saving the XML log file to xmlSavePath
        Dim piXmlLogPath As PropertyInfo = GetType(WinSCP.Session).GetProperty("XmlLogPath", BindingFlags.NonPublic Or BindingFlags.Instance)
        Dim xmlLogPath As String = piXmlLogPath.GetValue(ftpSession, Nothing)
        piXmlLogPath.SetValue(ftpSession, Nothing, Nothing) 'this prevents the xml log being deleted by WinSCP
        ftpSession.Dispose()    'this is necessary to complete the XML log
        'copy the xml log where we want it and then delete the original
        Dim fi As New FileInfo(xmlLogPath)
        fi.CopyTo(xmlSavePath, True)
End Sub

Re: XML Logging

Thanks for your post.

This request has been added to the tracker:

Meanwhile you can make a copy of the log just before calling Session.Dispose().

XML Logging

If possible, I'd like to retain the WinSCP XML log, preferably not in %TEMP%. Is there a way of configuring WinSCP.Session to use a specific XMLLog path and not delete it when the session is disposed?

Apologies if this has been asked before - I have looked! I realise this may not be simple, as the assembly uses the XML log to see what's going on in WinsSCP.

Thanks for a really useful bit of software; I wish I had found it earlier - System.Net.FtpWebRequest does have its limitations!

Using WinScp.dll v1.0.2.2735