Re: No XML log file using PowerShell and the .NET Assembly
What method is best for logging and archiving session uploads (success and failure)?
Handle
Session.FileTransferred
event:
https://winscp.net/eng/docs/library_session_filetransferred
What method is best for logging and archiving session uploads (success and failure)?
Session.FileTransferred
event:
The XML log file in used internally by the assembly. It is always created (no matter if you set the property or not) and deleted when session closes. The sole purpose of the property is to change a path where the temporary log is stored.
<?xml version="1.0" encoding="UTF-8"?>
<session xmlns="http://winscp.net/schema/session/1.0" name="ftpusername@1.2.3.4" start="2014-03-26T19:04:02.852Z">
<rm>
<filename value="/TEST/test.txt" />
<result success="true" />
</rm>
</session>
$session.XmlLogPath = "D:\some\path\here.xml"
$session
ExecutablePath :
AdditionalExecutableArguments :
DefaultConfiguration : True
DisableVersionCheck : True
IniFilePath :
ReconnectTime : 10675199.02:48:05.4775807
DebugLogPath :
SessionLogPath : D:\some\path\log.log
XmlLogPath :
Timeout : 00:01:00
Output : {winscp> option batch on, batch on , winscp> option confirm off, confirm off ...}
Opened :
UnderlyingSystemType : WinSCP.Session
# Load WinSCP .NET assembly
[Reflection.Assembly]::LoadFrom("D:\Program Files (x86)\WinSCP\WinSCPnet.dll") | Out-Null
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "1.2.3.4" <-- obviously not real IP
$sessionOptions.UserName = "someftpusername"
$sessionOptions.Password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bPswd)
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx::xx" <-obviously not real fingerprint
$session = New-Object WinSCP.Session
$Session.DisableVersionCheck = "1"
$Session.XmlLogPath = "D:\some\path\log.xml"
$Session.SessionLogPath = "D:\some\path\.log"