Sample code for 30+ languages & platforms
DataFlex

Change the Remote Directory (CWD)

See more FTP Examples

Demonstrates the Chilkat Ftp2.ChangeRemoteDir method, which changes the current working directory on the FTP server. The only argument is the remote directory path.

Background: This sends a single CWD with the path exactly as given; Chilkat does not split a multi-level path into one CWD per segment, so whether a/b/c works in one call depends on the server. A relative path moves from the current directory, while an absolute path (leading /) is resolved from the root according to the server's conventions. Confirm the result with GetCurrentRemoteDir when it matters.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFtp
    String sCurrentDir
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

    //  Demonstrates the Ftp2.ChangeRemoteDir method, which changes the current working directory on
    //  the FTP server.  The only argument is the remote directory 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"

    //  Connect and log in (Connect performs both).
    Get ComConnect Of hoFtp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  A relative path is resolved from the current remote directory; an absolute path (beginning
    //  with "/") is interpreted according to the server's path syntax.
    Get ComChangeRemoteDir Of hoFtp "public_html/images" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComGetCurrentRemoteDir Of hoFtp To sCurrentDir
    Get ComLastMethodSuccess Of hoFtp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Now in: " sCurrentDir

    Get ComDisconnect Of hoFtp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End



End_Procedure