home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 53 / IOPROG_53.ISO / soft / c++ / xceedftp.exe / Samples / Delphi / MethodDemo / Main.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-10-05  |  25.3 KB  |  601 lines

  1. unit Main;
  2. { ----------------------------------------------------------------- }
  3. { Xceed FTP Library - Method Demonstrator sample application        }
  4. { Copyright (c) 2000 Xceed Software Inc.                            }
  5. {                                                                   }
  6. { [frmXceedFTP.pas]                                                 }
  7. {                                                                   }
  8. {  This unit contains all the code for the Method Demonstrator      }
  9. {  sample application                                               }
  10. {                                                                   }
  11. {  This file is part of the Xceed FTP Library samples applications. }
  12. {  The source code in this file is only intended as a supplement    }
  13. {  to Xceed FTP Library's documentation, and is provided "as is",   }
  14. {  without warranty of any kind, either expressed or implied.       }
  15. { ----------------------------------------------------------------- }
  16.  
  17. interface
  18.  
  19. uses
  20.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  21.   OleCtrls, ComCtrls, StdCtrls, checklst, XceedFtpLib_TLB;
  22.  
  23. const
  24.   { Property hints }
  25.   cServerAddress = 'ServerAddress property:' + #13#10 +
  26.                    'Use this property to specify the address of the FTP' + #13#10 +
  27.                    'server to connect to. The address you specify can be either' + #13#10 +
  28.                    'a host name (ex: ftp.cdrom.com) or an IP address' + #13#10 +
  29.                    'in dot-notation (ex: 192.168.0.1). WINS computer names also work.';
  30.  
  31.   cServerPort = 'ServerPort property:' + #13#10 +
  32.                 'This property allows you to specify the port number of the FTP' + #13#10 +
  33.                 'server to connect to.';
  34.  
  35.   cUsername = 'Username property:' + #13#10 +
  36.               'Use this property to specify the user to log in when connecting' + #13#10 +
  37.               'to the FTP server.';
  38.  
  39.   cPassword = 'Password property:' + #13#10 +
  40.               'This property allows you to specify the password to use to log in' + #13#10 +
  41.               'to the FTP server if the user being logged in requires a password.' + #13#10 +
  42.               'If an invalid password is entered, the PasswordRequired event will be' + #13#10 +
  43.               'triggered.';
  44.  
  45.   cConnect = 'Connect method:' + #13#10 +
  46.              'Establishes a connection to an FTP server.' + #13#10 +
  47.              'The FTP server to connect to must be specified by setting the' + #13#10 +
  48.              'ServerAddress property. Please see the "applicable properties"' + #13#10 +
  49.              'section below to find out which other properties are referred to' + #13#10 +
  50.              'by this method.';
  51.  
  52.   cDisconnect = 'Disconnect method:' + #13#10 +
  53.                 'Terminates the connection with the FTP server.' + #13#10 +
  54.                 'If a file transfer is currently underway, it will be' + #13#10 +
  55.                 'aborted before disconnecting.';
  56.  
  57.   cListRemoteFolder = 'sFolderMask parameter of the ListFolderContents or' + #13#10 +
  58.                       'GetFolderContents method:' + #13#10 +
  59.                       'The remote folder that both methods will retreive the' + #13#10 +
  60.                       'contents of.';
  61.  
  62.   cPassiveMode = 'PassiveMode property:' + #13#10 +
  63.                  'This property affects the way the data connection is initiated.' + #13#10 +
  64.                  'False means that the client (the Xceed FTP Library) will listen for a data connection from the FTP server.' + #13#10 +
  65.                  'True (the default value) means that the library will initiate the data connection to the FTP server.';
  66.  
  67.   cListFolderContents = 'ListFolderContents method:' + #13#10 +
  68.                         'Retrieves the listing of a folder''s contents via the ListingFolderItem' + #13#10 +
  69.                         'event.';
  70.  
  71.   cGetFolderContents = 'GetFolderContents method:' + #13#10 +
  72.                        'Retrieves a listing of a folder''s contents in the form of an' + #13#10 +
  73.                        'XceedFtpFolderItems collection object. You must specify the type of object you' + #13#10 +
  74.                        'want to receive from this method with the eFormat parameter.';
  75.  
  76.   cLocalFilename = 'The sLocalFilename parameter of both the SendFile and ReceiveFile methods:' + #13#10 +
  77.                    'the full path and filename of the local file.';
  78.  
  79.   cRemoteFilename = 'The sRemoteFilename parameter of both the SendFile and the' + #13#10 +
  80.                     'ReceiveFile methods:' + #13#10 +
  81.                     'In the case of the SendFile method, it is the name of the file as it' + #13#10 +
  82.                     'should be sent to the FTP server. In the case of the ReceiveFile' + #13#10 +
  83.                     'method, it is the name of the file to receive.';
  84.  
  85.   cAllocateStorage = 'AllocateStorage property :' + #13#10 +
  86.                      'This property allows you to inform the library that the FTP' + #13#10 +
  87.                      'server requires the library to reserve enough space on the' + #13#10 +
  88.                      'server side before sending any files.';
  89.  
  90.   cAppend = 'bAppend parameter of the SendFile method:' + #13#10 +
  91.             'Set to True if you want to append to the remote file if it already exists.' + #13#10 +
  92.             'Set to False if you want to overwrite the remote file if it already exists';
  93.  
  94.   cRepType = 'RepresentationType property:' + #13#10 +
  95.              'This property allows you to specify the format of the' + #13#10 +
  96.              'data to send or receive (ASCII or binary).';
  97.  
  98.   cSendFile = 'SendFile method:' + #13#10 +
  99.               'Send a local file to the FTP server.';
  100.  
  101.   cReceiveFile = 'ReceiveFile method:' + #13#10 +
  102.                  'Receive a file from the FTP server.';
  103.  
  104.   cRemoteFilenameModification = 'sFilename parameter of both the DeleteFile and RenameFile methods:' + #13#10 +
  105.                                 'In the case of the DeleteFile method, it specifies the file that will' + #13#10 +
  106.                                 'be deleted from the FTP server. In the case of the RenameFile method,' + #13#10 +
  107.                                 'it specifies the name of the remote file that will be modified.';
  108.  
  109.   cRemoteFolderNameModification = 'The sNewFolder parameter of the CreateFolder method or the sFolder parameter of the RemoveFolder method:' + #13#10 +
  110.                                   'In the case of the CreateFolder method, the sNewFolder parameter specifies the name of the new folder' + #13#10 +
  111.                                   'that will be created in the Ftp server. In the case of the RemoveFolder method, it is the name of the' + #13#10 +
  112.                                   'folder that will be removed/deleted from the server.';
  113.  
  114.   cNewName = 'sNewName parameter of the RenameFile method:' + #13#10 +
  115.              'The new filename.';
  116.  
  117.   cDeleteFile = 'DeleteFile method:' + #13#10 +
  118.                 'Deletes a file on the FTP server.';
  119.  
  120.   cRenameFile = 'RenameFile method:' + #13#10 +
  121.                 'renames a file on the FTP server.';
  122.  
  123.   cCreateFolder = 'CreateFolder method:' + #13#10 +
  124.                   'Creates a folder on the remote server.';
  125.  
  126.   cRemoveFolder = 'RemoveFolder method:' + #13#10 +
  127.                   'Removes (deletes) a folder from the FTP server.';
  128.  
  129. type
  130.   TfrmMain = class(TForm)
  131.     Label1                    : TLabel;
  132.     shtList                   : TTabSheet;
  133.     shtConnect                : TTabSheet;
  134.     shtSendReceive            : TTabSheet;
  135.     shtItemHandling           : TTabSheet;
  136.     tabExamples               : TPageControl;
  137.     Label3                    : TLabel;
  138.     Label4                    : TLabel;
  139.     Label5                    : TLabel;
  140.     Label6                    : TLabel;
  141.     btConnect                 : TButton;
  142.     StatusBar1                : TStatusBar;
  143.     Label7                    : TLabel;
  144.     Label9                    : TLabel;
  145.     txtRemoteFolder           : TEdit;
  146.     chkPassiveMode            : TCheckBox;
  147.     btListFolderContents      : TButton;
  148.     Label17                   : TLabel;
  149.     txtLocalFilename          : TEdit;
  150.     Label20                   : TLabel;
  151.     txtRemoteFilename         : TEdit;
  152.     btSendFile                : TButton;
  153.     Label23                   : TLabel;
  154.     txtRemoteFilenameModif    : TEdit;
  155.     Label24                   : TLabel;
  156.     txtRemoteFolderNameModif  : TEdit;
  157.     btDeleteFile              : TButton;
  158.     barFile                   : TProgressBar;
  159.     barGlobal                 : TProgressBar;
  160.     txtUsername               : TEdit;
  161.     txtServerAddress          : TEdit;
  162.     txtServerPort             : TEdit;
  163.     txtPassword               : TEdit;
  164.     btDisconnect              : TButton;
  165.     btGetFolderContents       : TButton;
  166.     btReceiveFile             : TButton;
  167.     chkAllocateStorage        : TCheckBox;
  168.     chkAppend                 : TCheckBox;
  169.     chkPassiveMode2           : TCheckBox;
  170.     grpRepType                : TGroupBox;
  171.     optAscii                  : TRadioButton;
  172.     optBinary                 : TRadioButton;
  173.     Label2                    : TLabel;
  174.     txtNewName                : TEdit;
  175.     btRenameFile              : TButton;
  176.     btCreateFolder            : TButton;
  177.     btRemoveFolder            : TButton;
  178.     xFtp: TXceedFtp;
  179.     lblConnectionInfo: TLabel;
  180.     lstLogAndErrors: TListBox;
  181.     Label8: TLabel;
  182.     Label10: TLabel;
  183.     Label11: TLabel;
  184.     Label12: TLabel;
  185.     Label13: TLabel;
  186.     lstFolderListing: TListView;
  187.     lblSendReceiveInfo: TLabel;
  188.     Label14: TLabel;
  189.  
  190.     procedure FormCreate(Sender: TObject);
  191.     procedure btConnectClick(Sender: TObject);
  192.     procedure btListFolderContentsClick(Sender: TObject);
  193.     procedure btSendFileClick(Sender: TObject);
  194.     procedure btDeleteFileClick(Sender: TObject);
  195.     procedure xFtpListingFolderItem(Sender: TObject;
  196.       const sName: WideString; dtDate: TDateTime; lFileSize: Integer;
  197.       eItemType: TOleEnum; const sUserData: WideString);
  198.     procedure btDisconnectClick(Sender: TObject);
  199.     procedure btGetFolderContentsClick(Sender: TObject);
  200.     procedure btReceiveFileClick(Sender: TObject);
  201.     procedure btRenameFileClick(Sender: TObject);
  202.     procedure btCreateFolderClick(Sender: TObject);
  203.     procedure btRemoveFolderClick(Sender: TObject);
  204.     procedure xFtpFileTransferStatus(Sender: TObject; const sLocalFilename,
  205.       sRemoteFilename: WideString; lFileSize, lBytesTransferred: Integer;
  206.       nBytesPercent: Smallint; lTotalSize, lTotalBytesTransferred: Integer;
  207.       nTotalBytesPercent: Smallint; lTotalFiles,
  208.       lTotalFilesTransferred: Integer; nTotalFilesPercent: Smallint;
  209.       lBytesPerSecond, lTotalBytesPerSecond: Integer);
  210.     procedure xFtpReceivingFile(Sender: TObject;
  211.       const sRemoteFilename: WideString; var sLocalFilename: WideString;
  212.       lFileSize: Integer);
  213.     procedure xFtpSendingFile(Sender: TObject;
  214.       const sLocalFilename: WideString; var sRemoteFilename: WideString;
  215.       lFileSize: Integer);
  216.     procedure FormDestroy(Sender: TObject);
  217.     procedure xFtpDisconnected(Sender: TObject);
  218.     procedure xFtpSkippingFile(Sender: TObject; const sLocalFilename,
  219.       sRemoteFilename: WideString; lSkippingReason: Integer);
  220.     procedure xFtpLoggingCommandLine(Sender: TObject;
  221.       const sLine: WideString; eCommandType: TOleEnum);
  222.   private
  223.     { Private declarations }
  224.     procedure UpdateFieldHints;
  225.   public
  226.     { Public declarations }
  227.   end;
  228.  
  229. var
  230.   frmMain: TfrmMain;
  231.  
  232. implementation
  233.  
  234. {$R *.DFM}
  235.  
  236. {-----------------------------------------------------------------------------}
  237. { Update hints with linefeeds for better output                               }
  238. {-----------------------------------------------------------------------------}
  239.  
  240. procedure TfrmMain.UpdateFieldHints;
  241. begin
  242.   txtServerAddress.Hint := cServerAddress;
  243.   txtServerPort.Hint    := cServerPort;
  244.   txtUsername.Hint      := cUsername;
  245.   txtPassword.Hint      := cPassword;
  246.   btConnect.Hint        := cConnect;
  247.   btDisconnect.Hint     := cDisconnect;
  248.  
  249.   txtRemoteFolder.Hint      := cListRemoteFolder;
  250.   chkPassiveMode.Hint       := cPassiveMode;
  251.   btListFolderContents.Hint := cListFolderContents;
  252.   btGetFolderContents.Hint  := cGetFolderContents;
  253.  
  254.   txtLocalFilename.Hint   := cLocalFilename;
  255.   txtRemoteFilename.Hint  := cRemoteFilename;
  256.   chkAllocateStorage.Hint := cAllocateStorage;
  257.   chkAppend.Hint          := cAppend;
  258.   chkPassiveMode2.Hint    := cPassiveMode;
  259.   grpRepType.Hint         := cRepType;
  260.   btSendFile.Hint         := cSendFile;
  261.   btReceiveFile.Hint      := cReceiveFile;
  262.  
  263.   txtRemoteFilenameModif.Hint   := cRemoteFilenameModification;
  264.   txtRemoteFolderNameModif.Hint := cRemoteFolderNameModification;
  265.   txtNewName.Hint               := cNewName;
  266.   btDeleteFile.Hint             := cDeleteFile;
  267.   btRenameFile.Hint             := cRenameFile;
  268.   btCreateFolder.Hint           := cCreateFolder;
  269.   btRemoveFolder.Hint           := cRemoveFolder;
  270. end;
  271.  
  272. {-----------------------------------------------------------------------------}
  273. { We update hints for better look. We can't put linefeeds in property editor! }
  274. {-----------------------------------------------------------------------------}
  275.  
  276. procedure TfrmMain.FormCreate(Sender: TObject);
  277. begin
  278.   UpdateFieldHints;
  279. end;
  280.  
  281. {-----------------------------------------------------------------------------}
  282. { Connect to the FTP server                                                   }
  283. {-----------------------------------------------------------------------------}
  284.  
  285. procedure TfrmMain.btConnectClick(Sender: TObject);
  286. begin
  287.  
  288.   { Copy values from the form's fields into the XceedFtp object's properties }
  289.  
  290.   xFtp.ServerAddress := txtServerAddress.Text;
  291.   xFtp.ServerPort := StrToInt( txtServerPort.Text );
  292.   xFtp.UserName := txtUsername.Text;
  293.   xFtp.Password := txtPassword.Text;
  294.  
  295.   { Now run the Connect method }
  296.  
  297.   try
  298.     xFtp.Connect();
  299.     lblConnectionInfo.Caption := 'Status: Connected to ' + xFtp.ServerAddress;
  300.   except
  301.     on xErr: Exception do
  302.       lstLogAndErrors.Items.Add( 'ERROR: ' + xErr.Message );
  303.   end;
  304. end;
  305.  
  306. {-----------------------------------------------------------------------------}
  307. { The ListFolderContents method will trigger the ListingFolderItem event for  }
  308. { each item being listed                                                      }
  309. {-----------------------------------------------------------------------------}
  310.  
  311. procedure TfrmMain.btListFolderContentsClick(Sender: TObject);
  312. begin
  313.   lstFolderListing.Items.Clear();
  314.   try
  315.     xFtp.PassiveMode := chkPassiveMode.Checked;
  316.     xFtp.ListFolderContents( txtRemoteFolder.Text );
  317.   except
  318.     on xErr: Exception do
  319.       lstLogAndErrors.Items.Add( 'ERROR: ' + xErr.Message );
  320.   end;
  321. end;
  322.  
  323. {-----------------------------------------------------------------------------}
  324. { Send a file to the FTP server                                               }
  325. {-----------------------------------------------------------------------------}
  326.  
  327. procedure TfrmMain.btSendFileClick(Sender: TObject);
  328. begin
  329.   try
  330.     { Copy values from the form's fields into the XceedFtp object's properties }
  331.  
  332.     xFtp.AllocateStorage := chkAllocateStorage.Checked;
  333.     xFtp.PassiveMode := chkPassiveMode2.Checked;
  334.  
  335.     if optAscii.Checked then xFtp.RepresentationType := frtASCII;
  336.     if optBinary.Checked then xFtp.RepresentationType := frtBinary;
  337.  
  338.     { Run the SendFile method }
  339.  
  340.     xFtp.SendFile(txtLocalFilename.Text, 0, txtRemoteFilename.Text, chkAppend.Checked);
  341.     lblSendReceiveInfo.Caption := '';
  342.   except
  343.     on xErr: Exception do
  344.       lstLogAndErrors.Items.Add( 'ERROR: ' + xErr.Message );
  345.   end;
  346. end;
  347.  
  348. {-----------------------------------------------------------------------------}
  349. { Delete a file from the FTP server                                           }
  350. {-----------------------------------------------------------------------------}
  351.  
  352. procedure TfrmMain.btDeleteFileClick(Sender: TObject);
  353. begin
  354.   try
  355.     xFtp.DeleteFile(txtRemoteFilenameModif.Text);
  356.   except
  357.     on xErr:Exception do
  358.       lstLogAndErrors.Items.Add( 'ERROR: ' + xErr.Message );
  359.   end;
  360. end;
  361.  
  362. {-----------------------------------------------------------------------------}
  363. { The ListingFolderItem event will be triggered by the Xceed FTP Library for  }
  364. { each item that is being listed as a result of calling the                   }
  365. { ListFolderContents method                                                   }
  366. {-----------------------------------------------------------------------------}
  367.  
  368. procedure TfrmMain.xFtpListingFolderItem(Sender: TObject;
  369.   const sName: WideString; dtDate: TDateTime; lFileSize: Integer;
  370.   eItemType: TOleEnum; const sUserData: WideString);
  371. var
  372.   xItem : TListItem;
  373. begin
  374.   xItem := lstFolderListing.Items.Add;
  375.  
  376.   xItem.Caption := sName;
  377.   case eItemType of
  378.     fitFile   : xItem.SubItems.Add('File');
  379.     fitFolder : xItem.SubItems.Add('Dir');
  380.     fitLink   : xItem.SubItems.Add('Link');
  381.   end;
  382. end;
  383.  
  384. {-----------------------------------------------------------------------------}
  385. { Disconnect from FTP server. Requires no proerties to be set.                }
  386. {-----------------------------------------------------------------------------}
  387.  
  388. procedure TfrmMain.btDisconnectClick(Sender: TObject);
  389. begin
  390.   try
  391.     xFtp.Disconnect();
  392.     { The Disconnected event will be triggered, and in that event
  393.       we will update the lblConnectionInfo.Caption to show it }
  394.   except
  395.     on xErr: Exception do
  396.       lstLogAndErrors.Items.Add( 'ERROR: ' + xErr.Message );
  397.   end;
  398. end;
  399.  
  400. {-----------------------------------------------------------------------------}
  401. { The GetFolderContents method retrieves an XceedFtpFolderItems collection    }
  402. { containing information on each item in a remote folder. It does the same    }
  403. { thing as the ListFolderContents method, but does not trigger any events.    }
  404. {-----------------------------------------------------------------------------}
  405.  
  406. procedure TfrmMain.btGetFolderContentsClick(Sender: TObject);
  407. var
  408.   iFolderItems  : IXceedFtpFolderItems;
  409.   iItem         : IXceedFtpFolderItem;
  410.   nItemIndex    : integer;
  411.   vaIndex       : OleVariant;
  412.   xListItem     : TListItem;
  413. begin
  414.     lstFolderListing.Items.Clear();
  415.   try
  416.     xFtp.PassiveMode := chkPassiveMode.Checked;
  417.     iFolderItems := xFtp.GetFolderContents( txtRemoteFolder.Text, fcfCollection ) As IXceedFtpFolderItems;
  418.     nItemIndex := 1;
  419.  
  420.     while nItemIndex <= iFolderItems.Count do
  421.     begin
  422.       vaIndex := nItemIndex;
  423.       iItem := iFolderItems.Item[ vaIndex ];
  424.  
  425.       xListItem := lstFolderListing.Items.Add;
  426.  
  427.       xListItem.Caption := iItem.ItemName;
  428.       case iItem.ItemType of
  429.         fitFile   : xListItem.SubItems.Add('File');
  430.         fitFolder : xListItem.SubItems.Add('Dir');
  431.         fitLink   : xListItem.SubItems.Add('Link');
  432.       end;
  433.       nItemIndex := nItemIndex + 1;
  434.     end;
  435.   except
  436.     on xErr: Exception do
  437.       lstLogAndErrors.Items.Add( 'ERROR: ' + xErr.Message );
  438.   end;
  439. end;
  440.  
  441. {-----------------------------------------------------------------------------}
  442. { The ReceiveFile method will transfer a file from the FTP server to our      }
  443. { selected location. We can also rename the file or change its location.      }
  444. {-----------------------------------------------------------------------------}
  445.  
  446. procedure TfrmMain.btReceiveFileClick(Sender: TObject);
  447. begin
  448.   try
  449.  
  450.     { Copy values from the form's fields into the XceedFtp object's properties }
  451.  
  452.     xFtp.PassiveMode := chkPassiveMode2.Checked;
  453.  
  454.     { Run the ReceiveFile method }
  455.  
  456.     xFtp.ReceiveFile(txtRemoteFilename.Text, 0, txtLocalFilename.Text);
  457.     lblSendReceiveInfo.Caption := '';
  458.   except
  459.     on xErr:Exception do
  460.       lstLogAndErrors.Items.Add( 'ERROR: ' + xErr.Message );
  461.   end;
  462. end;
  463.  
  464. {-----------------------------------------------------------------------------}
  465. { Rename a file on the FTP server                                             }
  466. {-----------------------------------------------------------------------------}
  467.  
  468. procedure TfrmMain.btRenameFileClick(Sender: TObject);
  469. begin
  470.   try
  471.     xFtp.RenameFile(txtRemoteFilenameModif.Text, txtNewName.Text);
  472.   except
  473.     on xErr: Exception do
  474.       lstLogAndErrors.Items.Add( 'ERROR: ' + xErr.Message );
  475.   end;
  476. end;
  477.  
  478. {-----------------------------------------------------------------------------}
  479. { Create a new remote folder                                                  }
  480. {-----------------------------------------------------------------------------}
  481.  
  482. procedure TfrmMain.btCreateFolderClick(Sender: TObject);
  483. begin
  484.   try
  485.     xFtp.CreateFolder(txtRemoteFolderNameModif.Text);
  486.   except
  487.     on xErr: Exception do
  488.       lstLogAndErrors.Items.Add( 'ERROR: ' + xErr.Message );
  489.   end;
  490. end;
  491.  
  492. {-----------------------------------------------------------------------------}
  493. { Remove a folder from the FTP server                                         }
  494. {-----------------------------------------------------------------------------}
  495.  
  496. procedure TfrmMain.btRemoveFolderClick(Sender: TObject);
  497. begin
  498.   try
  499.     xFtp.RemoveFolder(txtRemoteFolderNameModif.Text);
  500.   except
  501.     on xErr: Exception do
  502.       lstLogAndErrors.Items.Add( 'ERROR: ' + xErr.Message );
  503.   end;
  504. end;
  505.  
  506. {-----------------------------------------------------------------------------}
  507. { The FileTransferStatus event provides statistics on the current transfer    }
  508. { operation                                                                   }
  509. {-----------------------------------------------------------------------------}
  510.  
  511. procedure TfrmMain.xFtpFileTransferStatus(Sender: TObject;
  512.   const sLocalFilename, sRemoteFilename: WideString; lFileSize,
  513.   lBytesTransferred: Integer; nBytesPercent: Smallint; lTotalSize,
  514.   lTotalBytesTransferred: Integer; nTotalBytesPercent: Smallint;
  515.   lTotalFiles, lTotalFilesTransferred: Integer;
  516.   nTotalFilesPercent: Smallint; lBytesPerSecond,
  517.   lTotalBytesPerSecond: Integer);
  518. begin
  519.   barFile.Position := nBytesPercent;
  520.   barGlobal.Position := nTotalBytesPercent;
  521. end;
  522.  
  523. {-----------------------------------------------------------------------------}
  524. { The ReceivingFile event informs our application that we are about to start  }
  525. { receiving data for a specific file. We can change the location and filename }
  526. { where the file will be received to by changing the sLocalFilename parameter }
  527. {-----------------------------------------------------------------------------}
  528.  
  529. procedure TfrmMain.xFtpReceivingFile(Sender: TObject;
  530.   const sRemoteFilename: WideString; var sLocalFilename: WideString;
  531.   lFileSize: Integer);
  532. begin
  533.   lstLogAndErrors.Items.Add('EVENT: ReceivingFile');
  534.   lblSendReceiveInfo.Caption := 'Receiving ' + sRemoteFilename;
  535. end;
  536.  
  537. {-----------------------------------------------------------------------------}
  538. { The SendingFile event informs our application that we are about to send a   }
  539. { file to the FTP server. During this event we can change the location and    }
  540. { filename where the file will be uploaded to by changing the                 }
  541. { sRemoteFilename parameter                                                   }
  542. {-----------------------------------------------------------------------------}
  543.  
  544. procedure TfrmMain.xFtpSendingFile(Sender: TObject;
  545.   const sLocalFilename: WideString; var sRemoteFilename: WideString;
  546.   lFileSize: Integer);
  547. begin
  548.   lstLogAndErrors.Items.Add('EVENT: SendingFile');
  549.   lblSendReceiveInfo.Caption := 'Sending ' + sLocalFilename;
  550. end;
  551.  
  552. { --------------------------------------------------------------------------- }
  553. { If form is closed, make sure we disconnect!
  554. { --------------------------------------------------------------------------- }
  555.  
  556. procedure TfrmMain.FormDestroy(Sender: TObject);
  557. begin
  558.   if xFtp.CurrentState <> fstNotConnected then
  559.     xFtp.Disconnect();
  560. end;
  561.  
  562. { --------------------------------------------------------------------------- }
  563. { The Disconnected event is triggered when the library disconnects, or        }
  564. { gets disconnected from the FTP server                                       }
  565. { --------------------------------------------------------------------------- }
  566.  
  567. procedure TfrmMain.xFtpDisconnected(Sender: TObject);
  568. begin
  569.   lstLogAndErrors.Items.Add('EVENT: Disconnected');
  570.   lblConnectionInfo.Caption := 'Status: Not connected';
  571.   lstFolderListing.Items.Clear;
  572. end;
  573.  
  574. { --------------------------------------------------------------------------- }
  575. { The SkippingFile event is triggered each time a file about to be sent       }
  576. { or received is skipped for any reason                                       }
  577. { --------------------------------------------------------------------------- }
  578.  
  579. procedure TfrmMain.xFtpSkippingFile(Sender: TObject; const sLocalFilename,
  580.   sRemoteFilename: WideString; lSkippingReason: Integer);
  581. begin
  582.   if sLocalFilename <> '' then
  583.     lstLogAndErrors.Items.Add('EVENT: SkippingFile (File: '+ sLocalFilename +')')
  584.   else
  585.     lstLogAndErrors.Items.Add('EVENT: SkippingFile (File: '+ sRemoteFilename +')')
  586. end;
  587.  
  588. { --------------------------------------------------------------------------- }
  589. { The LoggingCommandLine event is triggered whenever log information is       }
  590. { being provided by the Xceed FTP Library. You can use it for debugging.      }
  591. { --------------------------------------------------------------------------- }
  592.  
  593. procedure TfrmMain.xFtpLoggingCommandLine(Sender: TObject;
  594.   const sLine: WideString; eCommandType: TOleEnum);
  595. begin
  596.   lstLogAndErrors.Items.Add('LOG: ' + sLine)
  597. end;
  598.  
  599. end.
  600.  
  601.