I'm trying to set up a
FileTransferProgress
event handler for the first time,
and I read and followed the code example pretty closely. I set a break point at the entrance to the
FileTransferProgress()
function, then ran it in debug mode in Visual Studio code.
I chose a fairly large file (600K+) on a slow server so I could watch the transfer progress event working. But when I ran the script, the event handler was never called (i.e., the break point in the function was never reached).
I let the script run for over 5 minutes before killing it. No errors were ever issued, so I'm unclear how to troubleshoot this issue.
I don't know if this is relevant, but later, when I ran the script on a fairly fast server, the following appeared in the VSC terminal after script termination:
OverloadDefinitions
-------------------
void add_FileTransferProgress(WinSCP.FileTransferProgressEventHandler value)
FileTransferProgress($_)
My $PSVersionTable:
Name Value
---- -----
PSVersion 7.3.6
PSEdition Core
GitCommitId 7.3.6
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
My code to install the event handler:
$session.add_FileTransferProgress ` # Install event handler to monitor each file’s
({FileTransferProgress($_)}) # progress (from WinSCP Web site example)
$session.open($sessionOptions) # Connect to server
My event handler:
function FileTransferProgress {
param($e)
<#
.SYNOPSIS
Handler for the WinSCP Session.FileTransferProgress event. It shows the progress of the file currently being transferred.
.NOTES
The progress bar which this function updates is *different* from the parent progress bar: the parent shows the progress of the file queue as a *whole*.
#>
$parentID = $queueProgress.getID()
$childID = $parentID + 1
$percent = $e.fileProgress * 100
$speed = $e.cps
$activity = "{0:p0} complete, {1:n0} bytes/sec" -f $percent, $speed
Write-Progress -id $childID -parentId $parentID -activity $activity -percentComplete $percent
}
Any ideas on how to track down what the trouble might be?