Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Pre-Allocate Server Space Before an FTP Upload (ALLO)

See more FTP Examples

Demonstrates the AllocateSize property, which sends the FTP ALLO command to pre-allocate disk space on the server before an upload. Set it to the size in bytes of the file about to be uploaded.

Background: ALLO asks the server to reserve storage in advance, a requirement of certain legacy systems — older mainframes in particular — that need the exact file size up front to allocate a dataset. Modern servers allocate space dynamically and typically ignore or accept ALLO without needing it, so most applications never set this. Provide it only when targeting a host known to require pre-allocation.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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;

  //  AllocateSize sends the FTP ALLO command to pre-allocate disk space on the server before an
  //  upload.  It is rarely needed -- mainly for certain legacy systems that require the exact size
  //  in advance -- since most servers allocate space dynamically.  Set it to the size in bytes of
  //  the file about to be uploaded.
ERROR: Assignment type mismatch.  ExpressionType=int, atgType=uint

  success := ftp.PutFile('qa_data/bigfile.zip','uploads/bigfile.zip');
  if (success = False) then
    begin
      WriteLn(ftp.LastErrorText);
      Exit;
    end;
  WriteLn('Uploaded with pre-allocation.');

  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.