Winscp transfer event args into a log file in Powerhsell

Advertisement

seanfaria
Joined:
Posts:
6
Location:
Miami

Winscp transfer event args into a log file in Powerhsell

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:
$session.Open($sessionOptions)
$synchronizationResult =
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Both, "E:\path1\", "/path2/", $False) ,
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Both, "E:\path1\", "/path2/", $False)


Item 2:
$session.Open($sessionOptions)
$synchronizationResult =
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Both, "E:\path1\", "/path2/", $False)
$session.SynchronizeDirectories(
[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. :?:

Reply with quote E-mail

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
29,070
Location:
Prague, Czechia

Re: Winscp transfer event args into a log file in Powerhsell

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.

Reply with quote

seanfaria
Joined:
Posts:
6
Location:
Miami

Re: Winscp transfer event args into a log file in Powerhsell

martin wrote:

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.


Sorry about that and i figured it out.

Thank you

Reply with quote E-mail

Advertisement

You can post new topics in this forum