DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoFtp
Variant vSb
Handle hoSb
Boolean iIncludeBom
String sTemp1
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatFtp2)) To hoFtp
If (Not(IsComObjectCreated(hoFtp))) Begin
Send CreateComObject of hoFtp
End
Set ComHostname Of hoFtp To "ftp.example.com"
Set ComUsername Of hoFtp To "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.
Set ComPassword Of hoFtp To "myPassword"
Get ComConnect Of hoFtp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
// Build the text to upload.
Get Create (RefClass(cComChilkatStringBuilder)) To hoSb
If (Not(IsComObjectCreated(hoSb))) Begin
Send CreateComObject of hoSb
End
Get ComAppend Of hoSb "name,quantity" + (character(10)) To iSuccess
Get ComAppend Of hoSb "widgets,42" + (character(10)) To iSuccess
// Upload as UTF-8 without a byte-order mark.
Move False To iIncludeBom
Get pvComObject of hoSb to vSb
Get ComPutFileSb Of hoFtp vSb "utf-8" iIncludeBom "public_html/inventory.csv" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Uploaded text file."
Get ComDisconnect Of hoFtp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
End_Procedure