Topic "Winscp transfer event args into a log file in Powerhsell"

Author Message
[View user's profile]

Joined: 2017-11-08
Posts: 1
Location: Miami
I am new to this so forgive me if this is a stupid question.
I have completed my script but I don't understand why this is happening.
Powershell scripts:
Question 1:
Works perfectly:
# Print results
foreach ($transfer in $transferResult.Transfers)
Write-Host ("Successful upload of {0} " -f $transfer.FileName)
Write-LogInfo -Message "Successful upload of $transfer " -LogPath $LogpathDir -ToScreen

Doesn't work perfectly:
#Print Results
foreach($synchronization in $synchronizationResult.Uploads)
Write-Host ("Successful upload of {0} " -f $synchronization.FileName)
Write-LogInfo -Message "Successful upload of $synchronization" -LogPath $LogpathDir -ToScreen
Write-LogInfo -Message "Synchronization of InfoDoc folders is complete" -LogPath $LogpathDir -ToScreen

Question 2:
Item 1:
$synchronizationResult =
[WinSCP.SynchronizationMode]::Both, "E:\path1\", "/path2/", $False) ,
[WinSCP.SynchronizationMode]::Both, "E:\path1\", "/path2/", $False)

Item 2:
$synchronizationResult =
[WinSCP.SynchronizationMode]::Both, "E:\path1\", "/path2/", $False)
[WinSCP.SynchronizationMode]::Both, "E:\path1\", "/path2/", $False)

The only difference between item 1 and item 2 is the comma after the first set of paths. Why do they yield different results?
Without a comma you get options like uploads, downloads, removals, failures, isSuccess for session.SynchronizeDirectories which I want but stumbled on this by accident. Question
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27059
Location: Prague, Czechia
Question 1: What does it mean "Doesn't work perfectly"? For me both code examples do the same. Both log "Successful upload of WinSCP.TransferEventArgs", what does not seem as a useful log entry. But it's as expected. Use the syntax that you have in Write-Host.

Question 2: If you do not consume a function return value, it is piped to the output.

Both your question are generic PowerShell questions. They have nothing to do with WinSCP.

You can post new topics in this forum


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!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License