Sample code for 30+ languages & platforms
Xbase++

FTP Download File to a Stream

Demonstrates how to FTP download a file to a Chilkat stream.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oFtp
LOCAL oStreamObj

nSuccess := 0

//  This example assumes the Chilkat FTP2 API to have been previously unlocked.
//  See FTP2 Unlock Sample for sample code.

oFtp := CreateObject("Chilkat.Ftp2")

oFtp:Hostname := "my-ftp-server.com"
oFtp:Port := 21
oFtp:Username := "mFtpLogin"
oFtp:Password := "myFtpPassword"
oFtp:AuthTls := 1
oFtp:Passive := 1

//  Connect and login to the FTP server using TLS.
nSuccess := oFtp:Connect()
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

//  Move to the sub-directory (from the FTP user's home directory) where the file is located.
nSuccess := oFtp:ChangeRemoteDir("temp")
IF (nSuccess == 0)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

//  Stream to this local file:
oStreamObj := CreateObject("Chilkat.Stream")
oStreamObj:SinkFile := "c:/temp/qa_output/penguins2.jpg"

nSuccess := oFtp:GetFileToStream("penguins2.jpg", oStreamObj)
IF (nSuccess == 0)
    ? oFtp:LastErrorText
    oFtp:destroy()
    oStreamObj:destroy()
    RETURN
ENDIF

oFtp:Disconnect()

? "Success."

oFtp:destroy()
oStreamObj:destroy()