PowerBuilder
PowerBuilder
Download an FTP File into a BinData
See more FTP Examples
Demonstrates the Chilkat Ftp2.GetFileBd method, which downloads a remote file and appends its bytes to a BinData. The first argument is the remote file path and the second is the BinData. No decoding or line-ending conversion is performed.
Background: Downloading into memory avoids a temporary local file when you intend to hash, parse, or forward the bytes immediately. Because it appends, existing bytes in the
BinData are preserved — handy for concatenating several remote files, but clear it first when you want only this one. Since no conversion is applied, this is the safe way to pull content regardless of the current transfer type — which defaults to binary (SetTypeBinary), the recommended setting for essentially every file, text included. The SetTypeAscii mode applies legacy CRLF translation and is rarely needed.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ftp
oleobject loo_Bd
li_Success = 0
// Demonstrates the Ftp2.GetFileBd method, which downloads a remote file and appends its bytes to
// a BinData. The 1st argument is the remote file path and the 2nd is the BinData. No decoding
// or line-ending conversion is performed.
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 = "ftp.example.com"
loo_Ftp.Username = "myFtpLogin"
// Normally you would not hard-code the password in source. You should instead obtain it
// from an interactive prompt, environment variable, or a secrets vault.
loo_Ftp.Password = "myPassword"
li_Success = loo_Ftp.Connect()
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
return
end if
// The BinData is not cleared automatically, so clear it first for replacement behavior.
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")
li_Success = loo_Ftp.GetFileBd("public_html/image.png",loo_Bd)
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
destroy loo_Bd
return
end if
Write-Debug "Downloaded " + string(loo_Bd.NumBytes) + " bytes into memory."
li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
destroy loo_Bd
return
end if
destroy loo_Ftp
destroy loo_Bd