Tcl
Tcl
Check FTP Connection and Login Status
See more FTP Examples
Demonstrates the connection-status properties ConnectVerified, LoginVerified, ConnectFailReason, and Greeting.
Background: When
Connect fails, these properties separate the possible causes: ConnectVerified shows whether the TCP connection was established at all, LoginVerified whether authentication then succeeded, and ConnectFailReason gives a numeric code pinpointing the failure — far more actionable than a generic error for distinguishing, say, an unreachable host from a bad password. The Greeting captures the server's opening banner, sometimes useful for identifying the server or its policies.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"
# 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 != 1} then {
# ConnectFailReason gives a numeric code describing why Connect failed.
puts "Connect failed, reason code: [CkFtp2_get_ConnectFailReason $ftp]"
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
# After a successful connect, these flags report what succeeded.
puts "TCP connection verified: [CkFtp2_get_ConnectVerified $ftp]"
puts "Login verified: [CkFtp2_get_LoginVerified $ftp]"
# The Greeting property holds the server's initial greeting banner.
puts "Server greeting: [CkFtp2_greeting $ftp]"
set success [CkFtp2_Disconnect $ftp]
if {$success == 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
delete_CkFtp2 $ftp