Sample code for 30+ languages & platforms
Xbase++

PassiveUseHostAddr

See more FTP Examples

Some FTP servers need this option for passive data transfers. In passive mode, the data connection is initiated by the client sending a PASV command to the FTP server, and the FTP server responds with the IP address and port number where it is listening for the client's connection request. When the PassiveUseHostAddr property is set, the IP address in the PASV response is discarded and the IP address of the remote endpoint of the existing control connection is used instead.

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.example.com"
oFtp:Username := "login"
oFtp:Password := "password"

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

//  Set the PassiveUseHostAddr property.
oFtp:PassiveUseHostAddr := 1

//  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"

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

nSuccess := oFtp:Disconnect()

? "File Uploaded!"

oFtp:destroy()