DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoFtp
String sTemp1
Boolean bTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatFtp2)) To hoFtp
If (Not(IsComObjectCreated(hoFtp))) Begin
Send CreateComObject of hoFtp
End
Set ComHostname Of hoFtp To "ftp.example.com"
Set ComUsername Of hoFtp To "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.
Set ComPassword Of hoFtp To "myPassword"
Get ComConnect Of hoFtp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
// RestartNext requests that the NEXT transfer resume from existing content rather than starting
// over. It is consumed by that transfer and then automatically reset.
Set ComRestartNext Of hoFtp To True
// Resume a partially-downloaded file. Because RestartNext is set, the download continues from
// the current local file size.
Get ComGetFile Of hoFtp "public_html/bigfile.zip" "qa_output/bigfile.zip" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
// PartialTransfer indicates whether the most recent download received some, but not all, of the
// remote file -- distinguishing a mid-transfer failure from other outcomes.
Get ComPartialTransfer Of hoFtp To bTemp1
If (bTemp1) Begin
Showln "Only part of the file was received; another resume may be needed."
End
Else Begin
Showln "The file was fully received."
End
Get ComDisconnect Of hoFtp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
End_Procedure