DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoFtp
String sCurrentDir
String sTemp1
Boolean bTemp1
Move False To iSuccess
// 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.
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
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 "Current remote directory: " sCurrentDir
Get ComDisconnect Of hoFtp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
End_Procedure