wwSFTP::OnFtpBufferUpdate

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

o.OnFtpBufferUpdate(lnPercent, lnDownloadedBytes, lcRemotePath, lcMode)

Parameters

lnPercentComplete
The percentage complete for the upload in progress. Value is an Integer between 0-100.

lnDownloadedBytes Number of bytes that have been downloaded or uploaded so far.

lcRemotePath
The remote path of the file processing

lcMode
Current process mode:

  • download
  • upload

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 (deprecated)

© West Wind Technologies, 1996-2024 • Updated: 06/01/24
Comment or report problem with topic