XML Logging :: WinSCP (original) (raw)

XML logging is one of the WinSCP log formats. An XML log includes structured records describing operations done by WinSCP over session. The log format is protocol independent.

In many cases you do not have to deal with the XML log file directly. WinSCP .NET assembly can do it for you.

Advertisement

Advertisement

Purpose

Primary purpose of the XML logging is to provide machine-readable description of automatically performed operations, such as when using scripting.

The XML logging is useful e.g. to:

Note that while the XML logging can be used also for GUI sessions, it does not record background transfers.

Using

The XML logging, being used along with scripting, is most typically enabled from command-line, using [/xmllog](/eng/docs/commandline#logging) parameter. It can be enabled in preferences too.

An overall format of the XML log file follows:


The top level session tag represents one logical session, which may consist of several physical sessions, particularly when connection is lost. Attribute name refers to name of the logical session. Attribute start indicates time when the session was initiated.1

The session element includes child elements, where each element represents single log entry, i.e. single physical operation with remote file over the logical session.

Representing Operations in Log

Every entry in the XML log represents single physical operation over the session. Typically this would be an operation with remote file.

Single logical operation (in scripting or GUI) may actually involve multiple physical operations, each represented with separate log element. For example upload of file (e.g. using put scripting command) may be represented by up to three elements, upload for actual upload, touch for preserving timestamp and chmod for preserving permissions.

Note that some logical operations does not have corresponding log element (e.g. creation of symbolic link). Such operations are omitted from the XML log.

Representing Results/Errors

Results/Errors of Operations

Result of a specific operation is represented by child result element of respective operation element. The result element has boolean success attribute.

Advertisement

If success is false, result element will typically include one or more message elements with error message(s). The error message is free text, that may be language-, protocol- or even server-specific. So you should not try to process it automatically.

The following example is from English version, connected with SFTP protocol to OpenSSH server:

Cannot open remote file '/home/user/examplefile.txt'. No such file or directory. Error code: 2 Error message from server: No such file Request code: 3

With some protocols, each of the physical operations are performed individually. With some protocols, set of operations may be performed in atomic form. This may prevent mapping error to specific operation. In this case the error may be associated with more operations, resulting in its duplication in the XML log.

Some errors may not be associated with any operation in the XML log. This particularly happens when:

Results/Errors of Script

When the script fails (WinSCP exit code is 1), the top level session element or group element (when grouping is enabled) will include one or more failure elements, each containing one or more message elements with error message(s).

If the particular error was associated with a physical operation, the error message will be included both in result child element of the respective operation element and in failure child element of top level session element or group element.

Cannot create remote file '/home/user/examplefile.txt'. Permission denied. Error code: 3 Error message from server: Permission denied Request code: 3 Cannot create remote file '/home/user/examplefile.txt'. Permission denied. Error code: 3 Error message from server: Permission denied Request code: 3

Advertisement

Grouping Operations for Commands

When using the XML logging together with scripting, operations and failures belonging to the same command can be grouped using parent group element:

Cannot create remote file '/home/user/examplefile.txt'. Permission denied. Error code: 3 Error message from server: Permission denied Request code: 3 Cannot create remote file '/home/user/examplefile.txt'. Permission denied. Error code: 3 Error message from server: Permission denied Request code: 3

Grouping can be enabled on command-line.

Grouping is particularly useful, when you are continuously reading the XML log file. By receiving </group> you know that the command execution has finished.

Elements

All operation elements below have [result](#result) child element in addition to listed child elements.

The result child element is always present. Many other child elements may be absent in case of error.

call

Execution of arbitrary remote shell command (with SFTP and SCP protocols) or execution of a protocol command (with FTP protocol).

Elements:

Element Description
command Command (in value attribute)
destination Absolute path to current remote working directory (in value attribute)
output Command standard output (in value attribute)
erroroutput Command error output (in value attribute)

Advertisement

Example:

Associated script commands: [call](/eng/docs/scriptcommand%5Fcall)

checksum

Calculating a checksum of a remote file.

Elements:

Element Description
filename Absolute path to a remote file (in value attribute)
algorithm Name of a checksum algorithm used (in value attribute)
checksum Hex dump of a calculated checksum (in value attribute)

Example:

Associated script commands: [checksum](/eng/docs/scriptcommand%5Fchecksum)

chmod

Changing of permissions of one (or more) remote file.

Elements:

Element Description
filename Absolute path to remote file (in value attribute)
permissions Permissions in Unix format rwxrwxrwx (in value attribute)

Advertisement

With SCP protocol optional boolean attribute recursive indicates, if permissions were changed recursively with single operation.

Example:

Associated script commands: [chmod](/eng/docs/scriptcommand%5Fchmod), [keepuptodate](/eng/docs/scriptcommand%5Fkeepuptodate) -permissions, [put](/eng/docs/scriptcommand%5Fput) -permissions, [synchronize](/eng/docs/scriptcommand%5Fsynchronize) remote|both -permissions

cp

Duplication of one remote file or directory.

Elements:

Element Description
filename Absolute path to source local file (in value attribute)
destination Absolute path to destination remote file (in value attribute)

Example:

Associated script commands: [cp](/eng/docs/scriptcommand%5Fcp)

download

Downloading of single file.

Elements:

Element Description
filename Absolute path to source remote file (in value attribute)
destination Absolute path to destination local file (in value attribute)2
size Number of bytes transferred.

Advertisement

Example:

Associated script commands: [get](/eng/docs/scriptcommand%5Fget), [synchronize](/eng/docs/scriptcommand%5Fsynchronize) local|both

ls

Listing of remote directory (only when explicitly requested using [ls](/eng/docs/scriptcommand%5Fls) scripting command).

Elements:

Element Description
destination Absolute path to remote directory (in value attribute)
files Container of file elements

Elements of file element:

Element Description
filename Name of file without path (in value attribute)
type Type of file as in Unix ls command output, e.g. d for directory (in value attribute)
size Size of file in bytes (in value attribute)
modification Modification timestamp (in value attribute)1
permissions File permissions in Unix format rwxrwxrwx (in value attribute)
owner File owner (in value attribute)
group File group (in value attribute)

Example:

Advertisement

Associated script commands: [ls](/eng/docs/scriptcommand%5Fls)

mkdir

Creating of remote directory.

Elements:

Element Description
filename Absolute path to remote directory (in value attribute)

Example:

Associated script commands: [keepuptodate](/eng/docs/scriptcommand%5Fkeepuptodate), [mkdir](/eng/docs/scriptcommand%5Fmkdir), [put](/eng/docs/scriptcommand%5Fput), [synchronize](/eng/docs/scriptcommand%5Fsynchronize) remote|both

mv

Moving of one remote file or directory to different remote directory or renaming of one remote file or directory.

Elements:

Element Description
filename Absolute path to source local file (in value attribute)
destination Absolute path to destination remote file (in value attribute)2

Example:

Associated script commands: [mv](/eng/docs/scriptcommand%5Fmv)

rm

Deleting of one (or more) remote file or directory.

Advertisement

Elements:

Element Description
filename Absolute path to remote file of directory (in value attribute)

With SCP protocol optional boolean attribute recursive indicates, if remote directory was recursively deleted with all contained files with single operation.

Example:

Associated script commands: [get](/eng/docs/scriptcommand%5Fget) -delete, [keepuptodate](/eng/docs/scriptcommand%5Fkeepuptodate) -delete, [rm](/eng/docs/scriptcommand%5Frm), [rmdir](/eng/docs/scriptcommand%5Frmdir), [synchronize](/eng/docs/scriptcommand%5Fsynchronize) local|both -delete

stat

Listing of remote file attributes.

Elements:

Element Description
filename Absolute path to remote file (in value attribute)
file Container of file attributes. See specification in description of ls element. Note that file element within stat misses filename subelement, comparing to file element within ls/files.

Example:

Associated script commands: [stat](/eng/docs/scriptcommand%5Fstat)

upload

Uploading of single file.

Advertisement

Elements:

Element Description
filename Absolute path to source local file (in value attribute)
destination Absolute path to destination remote file (in value attribute)2
size Number of bytes transferred.

Example:

Associated script commands: [keepuptodate](/eng/docs/scriptcommand%5Fkeepuptodate), [put](/eng/docs/scriptcommand%5Fput), [synchronize](/eng/docs/scriptcommand%5Fsynchronize) remote|both

touch

Changing of remote file timestamp.

Elements:

Element Description
filename Absolute path to remote file (in value attribute)
modification Modification timestamp (in value attribute)1

Example:

Associated script commands: [keepuptodate](/eng/docs/scriptcommand%5Fkeepuptodate), [put](/eng/docs/scriptcommand%5Fput) -preservetime, [synchronize](/eng/docs/scriptcommand%5Fsynchronize) remote|both

Schema

An XML schema for the XML log is available at:http://winscp.net/schema/session/1.0

Advertisement

Example

Note that the [group](#group) elements will be included, if enabled only.

No such file or directory. Error code: 2 Error message from server: No such file Request code: 13 No such file or directory. Error code: 2 Error message from server: No such file Request code: 13

Interpreting/Parsing

General

To parse the XML log, use any XML parser available.

Advertisement

If possible, using WinSCP .NET assembly is the preferred approach, which hides away the XML log file from your application.

If you want to parse the XML log yourself anyway, see following guides to learn how to do that in different development environments:

Transforming XML Log to Text Output Using XSLT Transformation

You can use XSLT transformation to convert the XML log to plain text output (or any other format).

For example to generate a plain text list of successfully downloaded files from the following XML log (log.xml):

use the following XSLT (download.xslt):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:winscp="" title="undefined" rel="noopener noreferrer">http://winscp.net/schema/session/1.0"> <xsl:output method="text" encoding="UTF-8" /> <xsl:strip-space elements="*" /> <xsl:template match='winscp:download[winscp:result[@success="true"]]/winscp:filename'> <xsl:value-of select="@value" /> xsl:text

You can execute it using any XSLT processor:

Advertisement

The output will be:

/path/file1.txt /path/file2.txt

For a more complex example, see Custom directory listing format (CSV).