Sample code for 30+ languages & platforms
Visual FoxPro

FTP Upload / Download to a BinData Object

Demonstrates how to FTP upload the contents of a BinData object, and FTP downloads to the a BinData object.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loFtp
LOCAL loBdA
LOCAL lcRemoteFilename
LOCAL loBdB

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

loBdA = CreateObject('Chilkat.BinData')
loBdA.LoadFile("qa_data/jpg/penguins.jpg")

* Upload the contents of bdA to the FTP server.
lcRemoteFilename = "penguins.jpg"
lnSuccess = loFtp.PutFileBd(loBdA,lcRemoteFilename)
IF (lnSuccess <> 1) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    RELEASE loBdA
    CANCEL
ENDIF

* Download...
loBdB = CreateObject('Chilkat.BinData')
lnSuccess = loFtp.GetFileBd(lcRemoteFilename,loBdB)
IF (lnSuccess <> 1) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    RELEASE loBdA
    RELEASE loBdB
    CANCEL
ENDIF

* Verify that bdA and bdB have the exact same contents.
? "size of bdA: " + STR(loBdA.NumBytes)
IF (loBdA.ContentsEqual(loBdB) = 1) THEN
    ? "Contents are equal. Success."
ELSE
    ? "Contents are NOT equal.  Failed."
ENDIF

loFtp.Disconnect()

RELEASE loFtp
RELEASE loBdA
RELEASE loBdB