Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Append to Existing File on FTP Server
See more FTP Examples
Uploads a file to the FTP server. If the remote file (on the FTP server) does not already exist, it is created. Otherwise the uploaded file is appended to the remote file.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;
localFilePath: string;
remoteFilename: string;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
ftp := TFtp2.Create;
ftp.Hostname := 'ftp.myftpserver.com';
ftp.Username := 'myUsername';
ftp.Password := 'myPassword';
// Connect to the FTP server.
success := ftp.ConnectOnly();
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Authenticate with the FTP server.
success := ftp.LoginAfterConnectOnly();
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
localFilePath := '/someDirectory/hamlet.xml';
remoteFilename := 'hamlet.xml';
// Upload to the FTP server, creating the file if it does not yet exist
// on the FTP server, or appending to the remote file if it already exists.
success := ftp.AppendFile(localFilePath,remoteFilename);
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
ftp.Disconnect();
WriteLn('Success.');
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.