Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loFtp
LOCAL loSb
LOCAL lnIncludeBom

lnSuccess = 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.

loFtp = CreateObject('Chilkat.Ftp2')

loFtp.Hostname = "ftp.example.com"
loFtp.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.
loFtp.Password = "myPassword"

lnSuccess = loFtp.Connect()
IF (lnSuccess = 0) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    CANCEL
ENDIF

*  Build the text to upload.
loSb = CreateObject('Chilkat.StringBuilder')
loSb.Append("name,quantity" + CHR(10))
loSb.Append("widgets,42" + CHR(10))

*  Upload as UTF-8 without a byte-order mark.
lnIncludeBom = 0
lnSuccess = loFtp.PutFileSb(loSb,"utf-8",lnIncludeBom,"public_html/inventory.csv")
IF (lnSuccess = 0) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    RELEASE loSb
    CANCEL
ENDIF

? "Uploaded text file."

lnSuccess = loFtp.Disconnect()
IF (lnSuccess = 0) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    RELEASE loSb
    CANCEL
ENDIF

RELEASE loFtp
RELEASE loSb