Topic "Unable to log output from powershell script."

Author Message
gothbox
[View user's profile]

Joined: 2014-02-26
Posts: 7
Hi all!

I'm really new to powershell, and need some help figuring out why this script fails.

Here's the script:

try
{
# Load WinSCP .NET assembly
[Reflection.Assembly]::LoadFrom("WinSCPnet.dll") | Out-Null

# Setup session options
$SessionOptions.DisableVersionCheck
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "***"
$sessionOptions.UserName = "***"
$sessionOptions.Password = "***"
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 ***"
$session.SessionLogPath = "\\***\Log\Uploaded.log"
$session = New-Object WinSCP.Session

try
{
$session.ExecutablePath = "D:\Program Files (x86)\WinSCP\winscp.exe"
# Connect
$session.Open($sessionOptions)

$localPath = "\\***\testwebexp*.txt"
$remotePath = "/**/out/"
$backupPath = "\\***exp\processed\"

# Upload files, collect results
$transferResult = $session.PutFiles($localPath, $remotePath)

# Iterate over every transfer
foreach ($transfer in $transferResult.Transfers)
{
# Success or error?
if ($transfer.Error -eq $Null)
{
Write-Host ("Upload of {0} succeeded, moving to backup" -f
$transfer.FileName)
# Upload succeeded, move source file to backup
Move-Item $transfer.FileName $backupPath
}
else
{
Write-Host ("Upload of {0} failed: {1}" -f
$transfer.FileName, $transfer.Error.Message)
}
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}

exit 0
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}


The script works well when i remove the line :
$session.SessionLogPath = "\\linux1\v\prod\dataexch\no2\vismaservicessere\exp\Log\Uploaded.log"


But when i try to run it with the løine it fails with this error:
The property 'SessionLogPath' cannot be found on this object. Verify that the property exists and can be set.


These's somewhere where i need to include this, but im do dumt to figure it out myself.
Could anyone please give me a helping hand ?
Advertisements
gothbox
[View user's profile]

Joined: 2014-02-26
Posts: 7
Figured it out Smile

Had to put $session = New-Object WinSCP.Session before $session.SessionLogPath = "\\***\Log\Uploaded.log" and it worked Smile

But does anyone know if there is possible to log the size of the files transferred ?
gothbox
[View user's profile]

Joined: 2014-02-26
Posts: 7
as far as i understand i need to log to XML file, but im unsure if i need something more to log size of files transferred.

Anyone ?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
gothbox wrote:
But does anyone know if there is possible to log the size of the files transferred ?

Well, it's your local files, so you can query their size. Transfer size is the same (as you use binary mode transfer).
_________________
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