PowerBuilder
PowerBuilder
Execute an FTP Upload Plan
See more FTP Examples
Demonstrates the Chilkat Ftp2.PutPlan method, which executes a previously created upload plan. The first argument is the plan text and the second is the local path of a completion log that records each successful operation.
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: The completion log is what makes plan execution resumable: each successful upload is recorded, so if a run is interrupted, re-executing the same plan skips the operations already logged and continues where it left off — invaluable for a large transfer over a flaky connection. The plan's stored absolute remote paths are used regardless of the current remote directory, so execution is independent of session state.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ftp
oleobject loo_SbPlan
string ls_Plan
li_Success = 0
// Demonstrates the Ftp2.PutPlan method, which executes a previously created upload plan. The 1st
// argument is the plan text and the 2nd is the local path of a completion log.
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
// Load a plan that was previously created with CreatePlan.
loo_SbPlan = create oleobject
li_rc = loo_SbPlan.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_SbPlan.LoadFile("qa_output/upload_plan.txt","utf-8")
if li_Success = 0 then
Write-Debug loo_SbPlan.LastErrorText
destroy loo_Ftp
destroy loo_SbPlan
return
end if
ls_Plan = loo_SbPlan.GetAsString()
// Execute the plan. Each successful operation is recorded in the completion log, which lets an
// interrupted run be resumed without repeating completed uploads. The plan uses its stored
// absolute remote paths even if the current remote directory has changed.
li_Success = loo_Ftp.PutPlan(ls_Plan,"qa_output/upload_done.log")
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
destroy loo_SbPlan
return
end if
Write-Debug "Upload plan executed."
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