PureBasic
PureBasic
Set FTP Connection and Read Timeouts
See more FTP Examples
Demonstrates the timeout properties ConnectTimeout, ReadTimeout, and IdleTimeoutMs.
Background: The three timeouts guard different phases:
ConnectTimeout (in seconds) bounds how long a connection attempt blocks so an unreachable server fails promptly; ReadTimeout (seconds) limits how long a data connection may stall without new data; and IdleTimeoutMs (milliseconds) caps a lack of forward progress overall. Tuning them prevents a hung server or flaky link from freezing an automated job indefinitely.Chilkat PureBasic Downloads
IncludeFile "CkFtp2.pb"
Procedure ChilkatExample()
success.i = 0
ftp.i = CkFtp2::ckCreate()
If ftp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkFtp2::setCkHostname(ftp, "ftp.example.com")
CkFtp2::setCkUsername(ftp, "myFtpLogin")
; Maximum seconds to wait for the TCP connection to be accepted.
CkFtp2::setCkConnectTimeout(ftp, 15)
; Maximum seconds a data connection may go without receiving more data before timing out.
CkFtp2::setCkReadTimeout(ftp, 30)
; Maximum milliseconds without a control-channel response or forward progress before failing.
CkFtp2::setCkIdleTimeoutMs(ftp, 20000)
; 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.
CkFtp2::setCkPassword(ftp, "myPassword")
success = CkFtp2::ckConnect(ftp)
If success = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
Debug "Connected with custom timeouts."
success = CkFtp2::ckDisconnect(ftp)
If success = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndProcedure