Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 0
set ftp [new_CkFtp2]
CkFtp2_put_Hostname $ftp "ftp.example.com"
CkFtp2_put_Username $ftp "myFtpLogin"
# SocksVersion selects the proxy: 0 (default) = none, 4 = SOCKS4, 5 = SOCKS5.
CkFtp2_put_SocksVersion $ftp 5
CkFtp2_put_SocksHostname $ftp "socks.example.com"
CkFtp2_put_SocksPort $ftp 1080
# SOCKS5 supports username/password authentication; SOCKS4 uses only a user identifier.
CkFtp2_put_SocksUsername $ftp "myProxyLogin"
CkFtp2_put_SocksPassword $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_put_Password $ftp "myPassword"
set success [CkFtp2_Connect $ftp]
if {$success == 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
puts "Connected through the SOCKS proxy."
set success [CkFtp2_Disconnect $ftp]
if {$success == 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
delete_CkFtp2 $ftp