Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp
oleobject loo_BdA
string ls_RemoteFilename
oleobject loo_BdB

li_Success = 0

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

loo_Ftp = create oleobject
li_rc = loo_Ftp.ConnectToNewObject("Chilkat.Ftp2")
if li_rc < 0 then
    destroy loo_Ftp
    MessageBox("Error","Connecting to COM object failed")
    return
end if

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

// Connect to the FTP server.
li_Success = loo_Ftp.ConnectOnly()
if li_Success <> 1 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

// Authenticate with the FTP server.
li_Success = loo_Ftp.LoginAfterConnectOnly()
if li_Success <> 1 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

loo_BdA = create oleobject
li_rc = loo_BdA.ConnectToNewObject("Chilkat.BinData")

loo_BdA.LoadFile("qa_data/jpg/penguins.jpg")

// Upload the contents of bdA to the FTP server.
ls_RemoteFilename = "penguins.jpg"
li_Success = loo_Ftp.PutFileBd(loo_BdA,ls_RemoteFilename)
if li_Success <> 1 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    destroy loo_BdA
    return
end if

// Download...
loo_BdB = create oleobject
li_rc = loo_BdB.ConnectToNewObject("Chilkat.BinData")

li_Success = loo_Ftp.GetFileBd(ls_RemoteFilename,loo_BdB)
if li_Success <> 1 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    destroy loo_BdA
    destroy loo_BdB
    return
end if

// Verify that bdA and bdB have the exact same contents.
Write-Debug "size of bdA: " + string(loo_BdA.NumBytes)
if loo_BdA.ContentsEqual(loo_BdB) = 1 then
    Write-Debug "Contents are equal. Success."
else
    Write-Debug "Contents are NOT equal.  Failed."
end if

loo_Ftp.Disconnect()


destroy loo_Ftp
destroy loo_BdA
destroy loo_BdB