wwSFTP::OnFtpBufferUpdate

This event handler can be used to provide progress information and cancel long running downloads or uploads.

o.OnFtpBufferUpdate(lnbytesdownloaded,lnbufferreads,lccurrentchunk, lnTotalBytes, loFtp)

Parameters

lnbytesdownloaded
Number of bytes that have been received so far

lnbufferreads
Number of buffer reads that have been made

lccurrentchunk
The current chunk of data as a binary blob

lnTotalBytes
Total bytes of this download

loFtp
Instance of the wwSftp FoxPro class that was passed into the SFtpClient (.NET). You can read information off this object as well as set lCancelDownload=.T. to terminate a download or upload in process.

IMPORTANT: You have to pass this object in via loSftp.oSftp.wwSftp = loSftp before hooking up this event, in order for this object to be available in this method. If not set, loFtp comes back null in the handler.

Example

FUNCTION DownloadFile()

loFtp = CREATEOBJECT("wwSftp")

lcHost = "127.0.0.1"
lnPort = 23
lcUsername = "tester"
lcPassword = "password"

loFtp.cFtpServer = lcHost
loFtp.nFtpPort = lnPort
loFtp.cUsername = lcUsername
loFtp.cPassword = lcPassword

*** IMPORTANT:
*** For Progress information and Cancellation
*** we have to pass this instance to the .NET client
loFtp.oSFtp.wwSftp = loFtp

*** Set up the Event Binding - map to BufferUpdate() method below
BINDEVENT(loFtp,"OnFtpBufferUpdate",this,"OnBufferUpdate")

lcOutputFile = ".\tests\sailbig_downloaded.jpg"
DELETE FILE lcOutputFile

loFtp.FtpConnect()

lnResult = loFtp.FtpGetFileEx("sailbig.jpg",lcOutputFile)

loFtp.FtpClose()

this.AssertTrue(loFtp.lCancelDownload == .F.,"This download has been cancelled")
this.AssertTrue(lnResult == 0,loFtp.cErrorMsg)
this.AssertTrue(FILE(lcOutputFile))

ENDFUNC
*   DownloadFile


*** This is the Event Handler Implementation
FUNCTION OnBufferUpdate(lnbytesdownloaded,lnbufferreads,lccurrentchunk, lnTotalBytes, loFtp)

WAIT WINDOW NOWAIT TRANSFORM(lnBytesDownloaded) + " of " + TRANSFORM(lnTotalBytes)

*** Optionally cancel the download
IF (lnBytesDownloaded > 26000)
    *** This is the loFTP instance from above
    loFtp.lCancelDownload = .t.
ENDIF    

ENDFUNC

See also:

Class wwSFTP

© West Wind Technologies, 2023 • Updated: 12/10/21
Comment or report problem with topic