Sample code for 30+ languages & platforms
Xbase++

Get the Current Remote Directory (PWD)

See more FTP Examples

Demonstrates the Chilkat Ftp2.GetCurrentRemoteDir method, which returns the current working directory reported by the FTP server, normally via the PWD command. It takes no arguments.

Background: FTP is stateful: the server tracks a current working directory per session, and relative paths in later commands are resolved against it. Reading it back is useful to confirm where you are after a ChangeRemoteDir, or to record the starting directory so you can return to it. The value comes from the server, so it reflects the server's own path syntax and canonicalization.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oFtp
LOCAL cCurrentDir

nSuccess := 0

//  Demonstrates the Ftp2.GetCurrentRemoteDir method, which returns the current working directory
//  reported by the FTP server (normally via the PWD command).  It takes no arguments.

oFtp := CreateObject("Chilkat.Ftp2")

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

//  Connect and log in (Connect performs both).
nSuccess := oFtp:Connect()
IF (nSuccess == 0)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

cCurrentDir := oFtp:GetCurrentRemoteDir()
IF (oFtp:LastMethodSuccess == 0)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

? "Current remote directory: " + cCurrentDir

nSuccess := oFtp:Disconnect()
IF (nSuccess == 0)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

oFtp:destroy()