Sample code for 30+ languages & platforms
Xbase++

FTP Upload / Download to StringBuilder

Demonstrate how to upload from a Chilkat StringBuilder object, and download into a StringBuilder object.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oFtp
LOCAL oSbA
LOCAL nBIncludeBOM
LOCAL cRemoteFilename
LOCAL oSbB
LOCAL nBCaseSensitive

nSuccess := 0

//  This example assumes Chilkat Ftp2 to have been previously unlocked.
//  See Unlock Ftp2 for sample code.

oFtp := CreateObject("Chilkat.Ftp2")

oFtp:Hostname := "www.my-ftp-server.com"
oFtp:Username := "mFtpLogin"
oFtp:Password := "myFtpPassword"

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

//  Authenticate with the FTP server.
nSuccess := oFtp:LoginAfterConnectOnly()
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

oSbA := CreateObject("Chilkat.StringBuilder")
oSbA:LoadFile("qa_data/hamlet.xml", "utf-8")

//  Upload the contents of sbA to the FTP server.
nBIncludeBOM := 0
cRemoteFilename := "hamletFromSb.xml"
nSuccess := oFtp:PutFileSb(oSbA, "utf-8", nBIncludeBOM, cRemoteFilename)
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    oSbA:destroy()
    RETURN
ENDIF

//  Download...
oSbB := CreateObject("Chilkat.StringBuilder")
nSuccess := oFtp:GetFileSb(cRemoteFilename, "utf-8", oSbB)
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    oSbA:destroy()
    oSbB:destroy()
    RETURN
ENDIF

//  Verify that sbA and sbB have the exact same contents.
? "size of sbA: " + Str(oSbA:Length)
nBCaseSensitive := 1
IF (oSbA:ContentsEqualSb(oSbB, nBCaseSensitive) == 1)
    ? "Contents are equal. Success."
ELSE
    ? "Contents are NOT equal.  Failed."
ENDIF

oFtp:Disconnect()

oFtp:destroy()
oSbA:destroy()
oSbB:destroy()