PureBasic
PureBasic
Log In After ConnectOnly on an FTP Server
See more FTP Examples
Demonstrates the Chilkat Ftp2.LoginAfterConnectOnly method, which authenticates a control connection previously established by ConnectOnly. It takes no arguments, sends USER, PASS, and ACCT when required, then performs normal post-login initialization.
Background: This is the second half of the two-step connect. Beyond sending the credentials, it runs the same post-login setup
Connect would — for example issuing TYPE I and any auto-negotiated features — so the session ends up in the same ready state either way. The value of the split is entirely in what you can do in the gap between the two calls.Chilkat PureBasic Downloads
IncludeFile "CkFtp2.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the Ftp2.LoginAfterConnectOnly method, which authenticates a control connection
; previously established by ConnectOnly. It takes no arguments and sends USER, PASS, and (when
; required) ACCT, then performs normal post-login initialization.
ftp.i = CkFtp2::ckCreate()
If ftp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkFtp2::setCkHostname(ftp, "ftp.example.com")
CkFtp2::setCkPort(ftp, 21)
; First connect without logging in.
success = CkFtp2::ckConnectOnly(ftp)
If success = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
; Set credentials (for example, after inspecting the greeting), then log in.
CkFtp2::setCkUsername(ftp, "myFtpLogin")
CkFtp2::setCkPassword(ftp, "myPassword")
success = CkFtp2::ckLoginAfterConnectOnly(ftp)
If success = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
Debug "Logged in."
success = CkFtp2::ckDisconnect(ftp)
If success = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndProcedure