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

GTSageDev

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)
        fi.Delete()
End Sub
martin

Re: XML Logging

Thanks for your post.

This request has been added to the tracker:
https://winscp.net/tracker/942

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

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