PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkFtp2.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the Ftp2.ChangeRemoteDir method, which changes the current working directory on
; the FTP server. The only argument is the remote directory path.
ftp.i = CkFtp2::ckCreate()
If ftp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkFtp2::setCkHostname(ftp, "ftp.example.com")
CkFtp2::setCkUsername(ftp, "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.
CkFtp2::setCkPassword(ftp, "myPassword")
; Connect and log in (Connect performs both).
success = CkFtp2::ckConnect(ftp)
If success = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
; A relative path is resolved from the current remote directory; an absolute path (beginning
; with "/") is interpreted according to the server's path syntax.
success = CkFtp2::ckChangeRemoteDir(ftp,"public_html/images")
If success = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
currentDir.s = CkFtp2::ckGetCurrentRemoteDir(ftp)
If CkFtp2::ckLastMethodSuccess(ftp) = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
Debug "Now in: " + currentDir
success = CkFtp2::ckDisconnect(ftp)
If success = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndProcedure