| 1 | unit MainBox;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|---|
| 7 | Dialogs, StdCtrls, FTPTSend;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 | TForm1 = class(TForm)
|
|---|
| 11 | Log: TMemo;
|
|---|
| 12 | BExit: TButton;
|
|---|
| 13 | BAbout: TButton;
|
|---|
| 14 | Label2: TLabel;
|
|---|
| 15 | Label3: TLabel;
|
|---|
| 16 | Label4: TLabel;
|
|---|
| 17 | TargetSystemEdit: TEdit;
|
|---|
| 18 | TargetPortEdit: TEdit;
|
|---|
| 19 | TargetFileEdit: TEdit;
|
|---|
| 20 | BGetFile: TButton;
|
|---|
| 21 | BPutFile: TButton;
|
|---|
| 22 | OpenDialog: TOpenDialog;
|
|---|
| 23 | SaveDialog: TSaveDialog;
|
|---|
| 24 | procedure BAboutClick(Sender: TObject);
|
|---|
| 25 | procedure BExitClick(Sender: TObject);
|
|---|
| 26 | procedure BPutFileClick(Sender: TObject);
|
|---|
| 27 | procedure BGetFileClick(Sender: TObject);
|
|---|
| 28 | private
|
|---|
| 29 | { Private-Deklarationen }
|
|---|
| 30 | TFTPClient:TTFTPSend;
|
|---|
| 31 | public
|
|---|
| 32 | { Public-Deklarationen }
|
|---|
| 33 | end;
|
|---|
| 34 |
|
|---|
| 35 | var
|
|---|
| 36 | Form1: TForm1;
|
|---|
| 37 |
|
|---|
| 38 | implementation
|
|---|
| 39 |
|
|---|
| 40 | {$R *.dfm}
|
|---|
| 41 |
|
|---|
| 42 | procedure TForm1.BAboutClick(Sender: TObject);
|
|---|
| 43 | begin
|
|---|
| 44 | // Show a little About-Box
|
|---|
| 45 | Application.MessageBox('Synapse Demo Application, (c) 2003 by Christian Brosius','About...',MB_OK);
|
|---|
| 46 | end;
|
|---|
| 47 |
|
|---|
| 48 | procedure TForm1.BExitClick(Sender: TObject);
|
|---|
| 49 | begin
|
|---|
| 50 | // Close the TFTP-Client
|
|---|
| 51 | Close;
|
|---|
| 52 | end;
|
|---|
| 53 |
|
|---|
| 54 | procedure TForm1.BPutFileClick(Sender: TObject);
|
|---|
| 55 | begin
|
|---|
| 56 | if OpenDialog.Execute
|
|---|
| 57 | then
|
|---|
| 58 | begin
|
|---|
| 59 | // Create TFTPClient
|
|---|
| 60 | TFTPClient := TTFTPSend.Create;
|
|---|
| 61 | Log.Lines.Add('TFTPClient created');
|
|---|
| 62 |
|
|---|
| 63 | // Set Target-Parameter
|
|---|
| 64 | TFTPClient.TargetHost := TargetSystemEdit.Text;
|
|---|
| 65 | Log.Lines.Add('TargetSystem is ' + TFTPClient.TargetHost);
|
|---|
| 66 | TFTPClient.TargetPort := TargetPortEdit.Text;
|
|---|
| 67 | Log.Lines.Add('TargetPort is ' + TFTPClient.TargetPort);
|
|---|
| 68 |
|
|---|
| 69 | // Try sending file
|
|---|
| 70 | Log.Lines.Add('Try to send ' + OpenDialog.FileName);
|
|---|
| 71 | TFTPClient.Data.LoadFromFile(OpenDialog.FileName);
|
|---|
| 72 | if TFTPClient.SendFile(ExtractFileName(OpenDialog.FileName))
|
|---|
| 73 | then
|
|---|
| 74 | begin
|
|---|
| 75 | // Filetransfer successful
|
|---|
| 76 | Log.Lines.Add('File successfully sent to TFTPServer');
|
|---|
| 77 | end
|
|---|
| 78 | else
|
|---|
| 79 | begin
|
|---|
| 80 | // Filetransfer not successful
|
|---|
| 81 | Log.Lines.Add('Error while sending File to TFTPServer');
|
|---|
| 82 | Log.Lines.Add('Error #' + IntToStr(TFTPClient.ErrorCode) + ' - ' + TFTPClient.ErrorString);
|
|---|
| 83 | end;
|
|---|
| 84 | // Free TFTPClient
|
|---|
| 85 | TFTPClient.Free;
|
|---|
| 86 | Log.Lines.Add('TFTPClient destroyed');
|
|---|
| 87 | end;
|
|---|
| 88 | end;
|
|---|
| 89 |
|
|---|
| 90 | procedure TForm1.BGetFileClick(Sender: TObject);
|
|---|
| 91 | begin
|
|---|
| 92 | // Create TFTPClient
|
|---|
| 93 | TFTPClient := TTFTPSend.Create;
|
|---|
| 94 | Log.Lines.Add('TFTPClient created');
|
|---|
| 95 |
|
|---|
| 96 | // Set Target-Parameter
|
|---|
| 97 | TFTPClient.TargetHost := TargetSystemEdit.Text;
|
|---|
| 98 | Log.Lines.Add('TargetSystem is ' + TFTPClient.TargetHost);
|
|---|
| 99 | TFTPClient.TargetPort := TargetPortEdit.Text;
|
|---|
| 100 | Log.Lines.Add('TargetPort is ' + TFTPClient.TargetPort);
|
|---|
| 101 |
|
|---|
| 102 | // Try sending file
|
|---|
| 103 | Log.Lines.Add('Try to get "' + TargetFileEdit.Text + '"');
|
|---|
| 104 | if TFTPClient.RecvFile(TargetFileEdit.Text)
|
|---|
| 105 | then
|
|---|
| 106 | begin
|
|---|
| 107 | // Filetransfer successful
|
|---|
| 108 | Log.Lines.Add('File successfully get from TFTPServer');
|
|---|
| 109 | SaveDialog.FileName := TargetFileEdit.Text;
|
|---|
| 110 | if SaveDialog.Execute
|
|---|
| 111 | then TFTPClient.Data.SaveToFile(SaveDialog.FileName);
|
|---|
| 112 | end
|
|---|
| 113 | else
|
|---|
| 114 | begin
|
|---|
| 115 | // Filetransfer not successful
|
|---|
| 116 | Log.Lines.Add('Error while getting File from TFTPServer');
|
|---|
| 117 | Log.Lines.Add(IntToStr(TFTPClient.ErrorCode) + ' - ' + TFTPClient.ErrorString);
|
|---|
| 118 | end;
|
|---|
| 119 | // Free TFTPClient
|
|---|
| 120 | TFTPClient.Free;
|
|---|
| 121 | Log.Lines.Add('TFTPClient destroyed');
|
|---|
| 122 | end;
|
|---|
| 123 |
|
|---|
| 124 | end.
|
|---|