Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp
string ls_CurrentDir

li_Success = 0

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

loo_Ftp = create oleobject
li_rc = loo_Ftp.ConnectToNewObject("Chilkat.Ftp2")
if li_rc < 0 then
    destroy loo_Ftp
    MessageBox("Error","Connecting to COM object failed")
    return
end if

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

//  Connect and log in (Connect performs both).
li_Success = loo_Ftp.Connect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

//  A relative path is resolved from the current remote directory; an absolute path (beginning
//  with "/") is interpreted according to the server's path syntax.
li_Success = loo_Ftp.ChangeRemoteDir("public_html/images")
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

ls_CurrentDir = loo_Ftp.GetCurrentRemoteDir()
if loo_Ftp.LastMethodSuccess = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

Write-Debug "Now in: " + ls_CurrentDir

li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if



destroy loo_Ftp