Topic "No XML log file using PowerShell and the .NET Assembly"

Author Message
T
[View user's profile]

Joined: 2014-03-26
Posts: 2
Location: US
I'm trying to log transfers by modifying one of the supplied scripts in the script examples section. My transfers, and everything else works fine, but when I define:

Code:
$session.XmlLogPath = "D:\some\path\here.xml"


and run my script, the files get transferred, and I have a SessionLog...but no XML log. After the script is run, I run:

Code:
$session


to see what is defined, and the XmlLogPath is empty?

Code:
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


Below is what I have defined as my session and sessionOptions:



Code:
# 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"



Thoughts?

:edit: Removed a "#" from where I was testing something and forgot to uncomment the line before posting the code snippet.

Last edited by T on 2014-03-27 15:44; edited 1 time in total
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
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.
_________________
Martin Prikryl
T
[View user's profile]

Joined: 2014-03-26
Posts: 2
Location: US
prikryl wrote:
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.


Ok, when I set the XML Log path via the GUI, and perform an action, the .xml log is saved.

Code:
<?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>


I was looking to use the .xml log as opposed to the session.log because it's so much less garbled (a lot easier to read). What method is best for logging and archiving session uploads (success and failure)? I haven't had much luck finding information about logging in regards to PowerShell and the .NET Assembly.

thanks for the speedy response prikryl
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
T wrote:
What method is best for logging and archiving session uploads (success and failure)?

Handle Session.FileTransferred event:
http://winscp.net/eng/docs/library_session_filetransferred
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License