Sample code for 30+ languages & platforms
PowerBuilder

Create an FTP Upload Plan

See more FTP Examples

Demonstrates the Chilkat Ftp2.CreatePlan method, which creates and returns a textual upload plan for a local directory. The only argument is the local directory. The object must be connected, because the plan records the current absolute remote directory together with the local source paths.

Note: The local paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: A plan is a saved, resumable description of an upload — the list of local files and their absolute remote destinations — computed once and executed later (or on another run) with PutPlan. Separating planning from execution suits large or unreliable transfers: the plan can be reviewed, stored, and re-run, and because it records absolute remote paths it stays correct even if the working directory later changes.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp
string ls_Plan
oleobject loo_SbPlan

li_Success = 0

//  Demonstrates the Ftp2.CreatePlan method, which creates and returns a textual upload plan for a
//  local directory.  The only argument is the local directory.  The object must be connected,
//  because the plan records the current absolute remote directory.

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"

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

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

//  The plan captures which local files to upload and the absolute remote destination.  Save it so
//  the upload can be run (or resumed) later with PutPlan.
ls_Plan = loo_Ftp.CreatePlan("qa_data/site")
if loo_Ftp.LastMethodSuccess = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

//  Persist the plan text for later use.
loo_SbPlan = create oleobject
li_rc = loo_SbPlan.ConnectToNewObject("Chilkat.StringBuilder")

loo_SbPlan.Append(ls_Plan)
li_Success = loo_SbPlan.WriteFile("qa_output/upload_plan.txt")
if li_Success = 0 then
    Write-Debug loo_SbPlan.LastErrorText
    destroy loo_Ftp
    destroy loo_SbPlan
    return
end if

Write-Debug "Upload plan created."

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



destroy loo_Ftp
destroy loo_SbPlan