Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
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 Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Ftp2;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
ftp: TFtp2;
begin
success := False;
ftp := TFtp2.Create;
ftp.Hostname := 'ftp.example.com';
ftp.Username := '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.
ftp.Password := 'myPassword';
success := ftp.Connect();
if (success = False) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// 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).
ftp.CrlfMode := 1;
// CrlfMode applies only in ASCII transfer mode.
success := ftp.SetTypeAscii();
if (success = False) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
success := ftp.GetFile('public_html/readme.txt','qa_output/readme.txt');
if (success = False) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
WriteLn('Downloaded with CRLF line endings.');
success := ftp.Disconnect();
if (success = False) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
ftp.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.