Sample code for 30+ languages & platforms
Xbase++

Binary and ASCII FTP Transfer Modes

See more FTP Examples

The SetTypeBinary() and SetTypeAscii() method can be called to change the current transfer mode. The default transfer mode is binary. Once SetTypeAscii() or SetTypeBinary() is called, all subsequent transfers will occur in that mode.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oFtp
LOCAL cLocalFilename
LOCAL cRemoteFilename

nSuccess := 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oFtp := CreateObject("Chilkat.Ftp2")

oFtp:Hostname := "ftp.something.com"
oFtp:Username := "test"
oFtp:Password := "test"

//  Connect and login to the FTP server.
nSuccess := oFtp:Connect()
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

//  Set the transfer mode to ASCII
nSuccess := oFtp:SetTypeAscii()
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

//  Change to the remote directory where the file will be uploaded.
nSuccess := oFtp:ChangeRemoteDir("junk")
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

//  Upload a file.
cLocalFilename := "hamlet.xml"
cRemoteFilename := "hamlet.xml"

//  Turn on session logging for the upload:
oFtp:KeepSessionLog := 1

nSuccess := oFtp:PutFile(cLocalFilename, cRemoteFilename)
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

//  View the session log.  You can verify visually that
//  the transfer was in ascii mode.
? oFtp:SessionLog

nSuccess := oFtp:Disconnect()

? "File Uploaded!"

oFtp:destroy()