Tcl
Tcl
Control ASCII Download Line Endings (CrlfMode)
See more FTP Examples
Demonstrates the CrlfMode property, which controls line-ending conversion when downloading in ASCII transfer mode: 0 leaves them as received, 1 converts to CRLF, 2 to LF, and 3 to CR.
Background: When you deliberately download text in ASCII mode,
CrlfMode lets you force the saved file's line endings to a specific convention — CRLF for Windows tools, LF for Unix — regardless of what the server sends. It applies only in ASCII mode, so pair it with SetTypeAscii; in the recommended default binary mode, bytes are preserved verbatim and this setting has no effect. Reserve ASCII mode (and this property) for the rare case where line-ending normalization of text is actually wanted.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 == 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
# CrlfMode controls line-ending conversion for ASCII-mode downloads:
# 0 = leave line endings as received (default)
# 1 = convert to CRLF
# 2 = convert to LF
# 3 = convert to CR
# Convert a downloaded text file's line endings to CRLF (useful when saving for Windows).
CkFtp2_put_CrlfMode $ftp 1
# CrlfMode applies only in ASCII transfer mode.
set success [CkFtp2_SetTypeAscii $ftp]
if {$success == 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
set success [CkFtp2_GetFile $ftp "public_html/readme.txt" "qa_output/readme.txt"]
if {$success == 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
puts "Downloaded with CRLF line endings."
set success [CkFtp2_Disconnect $ftp]
if {$success == 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
delete_CkFtp2 $ftp