PureBasic
PureBasic
Connect to FTP Through a SOCKS Proxy
See more FTP Examples
Demonstrates connecting through a SOCKS proxy using SocksVersion, SocksHostname, SocksPort, SocksUsername, and SocksPassword.
Background: SOCKS is a general-purpose TCP relay, so it carries FTP transparently.
SocksVersion is the switch — 0 disables it, while 4 or 5 selects the protocol. SOCKS5 supports username/password authentication and is the usual choice; SOCKS4 supports only a user identifier. Because FTP opens separate data connections, a SOCKS proxy combined with passive mode is generally the most reliable arrangement.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")
; SocksVersion selects the proxy: 0 (default) = none, 4 = SOCKS4, 5 = SOCKS5.
CkFtp2::setCkSocksVersion(ftp, 5)
CkFtp2::setCkSocksHostname(ftp, "socks.example.com")
CkFtp2::setCkSocksPort(ftp, 1080)
; SOCKS5 supports username/password authentication; SOCKS4 uses only a user identifier.
CkFtp2::setCkSocksUsername(ftp, "myProxyLogin")
CkFtp2::setCkSocksPassword(ftp, "myProxyPassword")
; 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 SOCKS proxy."
success = CkFtp2::ckDisconnect(ftp)
If success = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndProcedure