Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

aksarben

Re: FileTransferProgress event handler not being called

I'm fairly new to PowerShell (couldn’t tell, could you?), and your reply surprised me. So, I Googled it and discovered there was a lot I didn’t now about line continuation! I never realized that subject area was filled with land mines!

Thanks for your patience and teaching! And yes, once I put it all on line line, it now works. Whew…
martin

Re: FileTransferProgress event handler not being called

This is not a WinSCP question. It's pure PowerShell syntax problem.
In PowerShell, you cannot put line breaks anywhere you like.
Just use the syntax you actually see in the example:
$session.add_FileTransferProgress( { FileTransferProgress($_) } )
aksarben

FileTransferProgress event handler not being called

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?