PowerBuilder
PowerBuilder
Upload Text to an FTP Server (StringBuilder)
See more FTP Examples
Demonstrates the Chilkat Ftp2.PutFileSb method, which encodes the text in a StringBuilder and uploads it to a remote path. The arguments are the StringBuilder, the charset, whether to include a byte-order mark, and the remote file path.
Background: The text-oriented upload: assemble a document — CSV, config, JSON — in a
StringBuilder and the method handles encoding as it writes. The charset governs the bytes actually stored, and the byte-order-mark flag is useful when a consuming Windows application expects a BOM.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ftp
oleobject loo_Sb
integer li_IncludeBom
li_Success = 0
// Demonstrates the Ftp2.PutFileSb method, which encodes the text in a StringBuilder and uploads
// it to a remote path. The 1st argument is the StringBuilder, the 2nd is the charset, the 3rd
// selects whether a byte-order mark is included, and the 4th is the remote file path.
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
// Build the text to upload.
loo_Sb = create oleobject
li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder")
loo_Sb.Append("name,quantity~n")
loo_Sb.Append("widgets,42~n")
// Upload as UTF-8 without a byte-order mark.
li_IncludeBom = 0
li_Success = loo_Ftp.PutFileSb(loo_Sb,"utf-8",li_IncludeBom,"public_html/inventory.csv")
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
destroy loo_Sb
return
end if
Write-Debug "Uploaded text file."
li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
destroy loo_Sb
return
end if
destroy loo_Ftp
destroy loo_Sb