Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Upload Multiple Files Matching Pattern
See more FTP Examples
The MPutFiles method can be called to upload all files matching a wildcarded filename pattern from a local filesystem directory.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;
numFilesUploaded: Integer;
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.example.com';
ftp.Username := 'my_login';
ftp.Password := 'my_password';
// Connect and login to the FTP server.
success := ftp.Connect();
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Change to the remote directory where the files will be uploaded.
// for the FTP account.
success := ftp.ChangeRemoteDir('junk');
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Upload all files with filenames matching "c:/temp/ftp_*.asp"
numFilesUploaded := ftp.MPutFiles('c:/temp/ftp_*.asp');
if (numFilesUploaded < 0) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
success := ftp.Disconnect();
WriteLn(numFilesUploaded + ' Files Uploaded!');
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.