PowerBuilder
PowerBuilder
Resume an Interrupted FTP Transfer
See more FTP Examples
Demonstrates the RestartNext and PartialTransfer properties, which request that the next transfer resume from existing content and report whether a download was incomplete.
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: For a large transfer over a flaky link, restarting from zero after a drop is wasteful. Setting
RestartNext makes the next download continue from the current local file size (and the next upload from the remote size); the flag is consumed by that one transfer and then reset. Afterward PartialTransfer tells you whether the download got only part of the file — the signal to set RestartNext again and resume once more.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ftp
li_Success = 0
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
// RestartNext requests that the NEXT transfer resume from existing content rather than starting
// over. It is consumed by that transfer and then automatically reset.
loo_Ftp.RestartNext = 1
// Resume a partially-downloaded file. Because RestartNext is set, the download continues from
// the current local file size.
li_Success = loo_Ftp.GetFile("public_html/bigfile.zip","qa_output/bigfile.zip")
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
return
end if
// PartialTransfer indicates whether the most recent download received some, but not all, of the
// remote file -- distinguishing a mid-transfer failure from other outcomes.
if loo_Ftp.PartialTransfer then
Write-Debug "Only part of the file was received; another resume may be needed."
else
Write-Debug "The file was fully received."
end if
li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
return
end if
destroy loo_Ftp