PureBasic
PureBasic
Connect to FTP Through an HTTP Proxy
See more FTP Examples
Demonstrates connecting through an HTTP proxy using HttpProxyHostname, HttpProxyPort, HttpProxyUsername, HttpProxyPassword, HttpProxyAuthMethod, and HttpProxyDomain.
Background: Many corporate networks force outbound traffic through an HTTP proxy, which reaches the FTP control connection via the
CONNECT method — so the proxy must permit CONNECT to the FTP port. HttpProxyAuthMethod is Basic or NTLM, with HttpProxyDomain supplying the Windows domain for NTLM. This is distinct from a traditional FTP proxy, which speaks FTP itself.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")
; The HTTP proxy through which the FTP control connection is made. Common ports are 8080 and
; 3128.
CkFtp2::setCkHttpProxyHostname(ftp, "proxy.example.com")
CkFtp2::setCkHttpProxyPort(ftp, 8080)
; Proxy authentication, if required. HttpProxyAuthMethod is "Basic" or "NTLM"; HttpProxyDomain
; is the Windows domain used for NTLM.
CkFtp2::setCkHttpProxyUsername(ftp, "myProxyLogin")
CkFtp2::setCkHttpProxyPassword(ftp, "myProxyPassword")
CkFtp2::setCkHttpProxyAuthMethod(ftp, "NTLM")
CkFtp2::setCkHttpProxyDomain(ftp, "CORP")
; 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 through the HTTP proxy."
success = CkFtp2::ckDisconnect(ftp)
If success = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndProcedure