Sample code for 30+ languages & platforms
Visual FoxPro

FTP Download with Progress Event Callbacks

See more FTP Examples

FTP download with progress event callbacks.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loFtp
LOCAL lcLocalFilename
LOCAL lcRemoteFilename

lnSuccess = 0

*  This example requires the Chilkat API to have been previously unlocked.
*  See Global Unlock Sample for sample code.

loFtp = CreateObject('Chilkat.Ftp2')
ftpEventHandler = CreateObject("ftpEvents")
EventHandler(loFtp,ftpEventHandler)

loFtp.Hostname = "ftp.someFtpServer.com"
loFtp.Username = "myLogin"
loFtp.Password = "myPassword"

*  Connect and login to the FTP server.
lnSuccess = loFtp.ConnectOnly()
IF (lnSuccess <> 1) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    CANCEL
ENDIF

lnSuccess = loFtp.LoginAfterConnectOnly()
IF (lnSuccess <> 1) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    CANCEL
ENDIF

*  Change to the remote directory where the file is located.
*  This step is only necessary if the file is not in the home directory
*  of the FTP account.
lnSuccess = loFtp.ChangeRemoteDir("junk")
IF (lnSuccess <> 1) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    CANCEL
ENDIF

lcLocalFilename = "c:/temp/hamlet.xml"
lcRemoteFilename = "hamlet.xml"

*  Ensure that we get PercentDone callbacks.
loFtp.AutoGetSizeForProgress = 1

*  Download the file.
lnSuccess = loFtp.GetFile(lcRemoteFilename,lcLocalFilename)
IF (lnSuccess <> 1) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    CANCEL
ENDIF

lnSuccess = loFtp.Disconnect()

? "File Downloaded!"

RELEASE loFtp

[K]DEFINE CLASS[/K] ftpEvents [K]AS SESSION OLEPUBLIC[/K]
[K]IMPLEMENTS[/K] _IChilkatFtp2Events [K]IN[/K] "Chilkat.Ftp2"

[K]PROCEDURE[/K] _IChilkatFtp2Events_AbortCheck(abort [K]As[/K] [K]Number[/K])
    [C]* Application code goes here...[/C]

[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_BeginDownloadFile(path [K]As[/K] [K]String[/K], nSkip [K]As[/K] [K]Number[/K])
    [C]* Application code goes here...[/C]
[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_BeginUploadFile(path [K]As[/K] [K]String[/K], nSkip [K]As[/K] [K]Number[/K])
    [C]* Application code goes here...[/C]
[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_BinaryData(data [K]As[/K] [K]Variant[/K])
    [C]* Application code goes here...[/C]

[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_DownloadRate(byteCount [K]As[/K] [K]Number[/K], bytesPerSec [K]As[/K] [K]Number[/K])
    [C]* Application code goes here...[/C]
[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_EndDownloadFile(path [K]As[/K] [K]String[/K], byteCount [K]As[/K] [K]Number[/K])
    [C]* Application code goes here...[/C]
[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_EndUploadFile(path [K]As[/K] [K]String[/K], byteCount [K]As[/K] [K]Number[/K])
    [C]* Application code goes here...[/C]
[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_PercentDone(pctDone [K]As[/K] [K]Number[/K], abort [K]As[/K] [K]Number[/K])
    [C]* Application code goes here...[/C]
    ? "Percent Done: " + STR(pctDone)
[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_ProgressInfo(name [K]As[/K] [K]String[/K], value [K]As[/K] [K]String[/K])
    [C]* Application code goes here...[/C]
    ? name + ": " + value
[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_TaskCompleted(task [K]As[/K] [K]Generic[/K])
    [C]* Application code goes here...[/C]

[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_TextData(data [K]As[/K] [K]String[/K])
    [C]* Application code goes here...[/C]

[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_UploadRate(byteCount [K]As[/K] [K]Number[/K], bytesPerSec [K]As[/K] [K]Number[/K])
    [C]* Application code goes here...[/C]
[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_VerifyDeleteDir(path [K]As[/K] [K]String[/K], nSkip [K]As[/K] [K]Number[/K])
    [C]* Application code goes here...[/C]
[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_VerifyDeleteFile(path [K]As[/K] [K]String[/K], nSkip [K]As[/K] [K]Number[/K])
    [C]* Application code goes here...[/C]
[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_VerifyDownloadDir(path [K]As[/K] [K]String[/K], nSkip [K]As[/K] [K]Number[/K])
    [C]* Application code goes here...[/C]
[K]ENDPROC[/K]

[K]PROCEDURE[/K] _IChilkatFtp2Events_VerifyUploadDir(path [K]As[/K] [K]String[/K], nSkip [K]As[/K] [K]Number[/K])
    [C]* Application code goes here...[/C]
[K]ENDPROC[/K]


[K]ENDDEFINE[/K]