Sample code for 30+ languages & platforms
Visual FoxPro

FTP Upload / Download to StringBuilder

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

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loFtp
LOCAL loSbA
LOCAL lnBIncludeBOM
LOCAL lcRemoteFilename
LOCAL loSbB
LOCAL lnBCaseSensitive

lnSuccess = 0

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

loFtp = CreateObject('Chilkat.Ftp2')

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

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

* Authenticate with the FTP server.
lnSuccess = loFtp.LoginAfterConnectOnly()
IF (lnSuccess <> 1) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    CANCEL
ENDIF

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

* Upload the contents of sbA to the FTP server.
lnBIncludeBOM = 0
lcRemoteFilename = "hamletFromSb.xml"
lnSuccess = loFtp.PutFileSb(loSbA,"utf-8",lnBIncludeBOM,lcRemoteFilename)
IF (lnSuccess <> 1) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    RELEASE loSbA
    CANCEL
ENDIF

* Download...
loSbB = CreateObject('Chilkat.StringBuilder')
lnSuccess = loFtp.GetFileSb(lcRemoteFilename,"utf-8",loSbB)
IF (lnSuccess <> 1) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    RELEASE loSbA
    RELEASE loSbB
    CANCEL
ENDIF

* Verify that sbA and sbB have the exact same contents.
? "size of sbA: " + STR(loSbA.Length)
lnBCaseSensitive = 1
IF (loSbA.ContentsEqualSb(loSbB,lnBCaseSensitive) = 1) THEN
    ? "Contents are equal. Success."
ELSE
    ? "Contents are NOT equal.  Failed."
ENDIF

loFtp.Disconnect()

RELEASE loFtp
RELEASE loSbA
RELEASE loSbB