: IdTrivialFTP IdTrivialFTPServer .
1.
.
TFTP.
IdTrivialFTP.
IdTrivialFTPServer.
1.1. TFTP
TFTP- - . UDP , . TFTP . , 8- Internet.
UDP, TFTP - , . . T.
TFTP :
1) read request (RRQ) - ;
2) write request (WRQ) - ;
3) data (DATA) - ;
4) acknowledgment () - ;
5) error (ERROR) - .
TFTP . - WRQ, - RRQ.
( ) -TID, UDP . TID, . TFTP- UQP- 69 ( ), . , .
, ( 512 ). (512 ) . () . .
512 . , .
:
1) , , , ;
2) , , ;
3) .
.
|
|
TFTP- :
1) WRQ . - TID, - 69. , (ascii, 8 .);
2) ( - 0) .
TIDB, -T1DA;
3) ( TIDA - TIDB) DATA . .
TFTP Delphi : IdTrivialFTP dTrivialFTPServer.
1.2. - idTrivialFTP
IdTrivialFTP TFTP-. - :
;
.
TF- Host IdTrivialF. :
IdTrivialFTPl.Host:= Edit1.Text.
Port IdTrivialFTP - 69.
:
IdTrivialFTP1.Put(const LocalFile:String; const ServerFile:String;), LocalFile - , , a ServerFile - , .
:
IdTrivialFTP1.Get IdTrivialFTP1.Get (const ServerFile:String; DestinationStream: TStream;),
ServerFile - , , a DestinationStream - , .
1.3. IdTrivialFTPServer
IdTrivialFTPServer TFTP-. - :
;
;
.
DefaultPort IdTrivialFTPServer -69.
TFTP- Active True. : IdTrivialFTPServer1.Active:=True.
TFTP- , . .
.
OnReadFile - . ;
OnWriteFile - . , , ;
OnTransferComplete - / . , , .
2.
2.1.
, . 1.
. 1
.
|
|
1) , . 1.
1
Edit1 | TEdit | , |
Label1 | TLabel | |
Memo1 | TMemo1 | , TFTP- |
DirectoryListBox1 | TDirectoryList-Box1 | ( Win 3.1 ) |
DriveComboBox1 | TDriveComboBox1 | , ( Win 3.1 ) |
IdTrivialFTPServer1 | TIdTrivialFTPServer | FT- ( Indy Servers ) |
2) OnCreate :
procedure TForm1.FormCreate(Sender: TObject);
begin
//
Edit1.Text:= GetCurrentDir;
// TFT-
IdTrivialFTPServerl.Active:=True;
end;.
3) OnChange DriveomboBox1 :
procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
DirectorylistBox1.Drive:= DriveComboBoxl.Drive;
end;.
DirectoryListBoxl .
4) OnChange DriveComboBox1 :
procedure TForm1.DirectoryListBoxlClick(Sender: TObject);
begin
Edit1.Text:=DirectoryListBoxl.GetItemPath(DirectoryListBox1.ItemIndex);
end;.
Edit1 .
5) OnReadFile IdTrivialFTPServer1 :
procedure TForm1.IdTrivilFTPServerlReadFile(Sender: TObject;
var FileName: String; const Peerinfo: TPeerlnfo;
var GrantAccess: Boolean; var A Stream: TStream;
var FreeStreamOnComplete: Boolean);
VAR
s: String;
begin
FreeStreamOnComplete:= false;
s:= ~';
try
If GrantAccess then
Begin
s:='- ';
end;
finally
memo1.Lines.Add(Format('%s: %d - %s %s',
[PeerInfo.PeerIP, PeerInfo.PeerPort, Filename, s]));
end;
end;.
, . , . , Memo1 .
6) OnWriteFile IdTrivialFTPServer1 :
procedure TForm1.IdTrivialFTPServer1WriteFile(Sender: TObject;
var FileName: Siring; const PeerInfo: TPeerInfo;
var GrantAccess: Boolean; var AStream: TStream;
var FreeStreamOnComplete: Boolean);
VAR
s: String;
begin
FreeStreamOnComplete:=false;
s:='- ';
try
If Grant Access then
begin
s:='- ';
end;
finally
memo1.Lines.Add(Format('%s: %d - %s %s',
[PeerInfo.PeerIP, PeerInfo.PeerPort.Filename,s]));
end;
end;.
, . , . , Memo1 .
7) OnTransferComplete IdTrivialFTPServer1 :
procedure TForm1.IdTrivialFTPServer1TransferComplete(Sender: TObject; const Success: Boolean; const PeerInfo: TPeerInfo; AStream: TStream;
const WriteOperation: Boolean);
Var s: String;
begin
try
If Success then s:= ' '
else s:=' ';
memo1.Lines.Add(Format('%s: %d - %s',
[PeerInfo.PeerIP, PeerInfo.PeerPort, s]));
|
|
finally
AStream.Free;
end;
end;.
, , or . , Memo1 .
8) .
2.2.
, . 2.
. 2
.
1) , . 2.
2) OnClick :
procedure TForm1.Button1Click(Sender: TObject);
begin
If Open Dialog1.Execute then
Edit3.Text:= OpenDialog1.FileName;
end;.
Edit3 . TFTP- . TFTP- .
Edit1 | TEdit | TF- |
Edit2 | TEdit | |
Edit3 | TEdit | |
Label1 | TLabel | FTP- |
Label2 | TLabel | |
Label3 | TLabel | |
OpenDialog1 | TOpenDialog | ( Dialogs ) |
IdTrivialFTPS1 | TIdTrivialFTP | TFTP- ( Indy Clients ) |
Button1 | TButton | |
Button2 | TButton | |
Button3 | TButton |
3) OnClick :
procedure TForm1.Button2Click(Sender: TObject);
Var s: String;
begin
//
S:=Edit2.Text:
// ,
//
If s=" then s:=ExtractFilename(Edit3.Text);
With IdTrivialFTP1 do
begin
//
Host:=Edit1.Text;
//
Put(Edit3.Text,s)
end;
end;.
4) OnClick :
procedure TForm1.Button3Click(Sender: TObject);
VAR
strm TFileStream;
s: String;
begin
//
s:= Edit3.Text;
// ,
//
If s= then ExtractFilename(Edit2.Text);
strm:= TFileStream.Create(s, fmCreate);
With IdTrivialFTP1 do
try
//
Host:=Edit1.Text;
//
Get(Edit2.Text, strm);
Finally
strm.Free;
end;
end;.
5) .
6) .
. Delphi /. . ., , 2003. 640 .
1. TFTP.
2. TFTP SNTP FTP.
3. TFTP- ?
4. TFTP- ?
5. TFTP- ?
|
|
6. TFTP ?
7. TFTP?
18
HTTP -
HTTP- HTTP:
GET - html- Internet;
TRACE - Internet. GET, -, html-;
PUT html- Internet.
: IdHTTP WEB-.
1.
IdHTTP.
1.1. IdHTTP
IdHTTP HTTP ( 1.0 1.1, GET, POST HEAD). , -.
1.1.1. GET
GET html- WEB-. Id .
Procedure Get(AURL: String; const AResponseContent: TStream), AURL - URL-pecypca (html-), ; AResponseContent - , .
Function Get (AURL: String): Siring,
AURL - URL-pecypca (html-), . .
1.1.2. TRACE
TRACE html- c WEB-. IdHTTP :
Procedure Trace(AURL: String; const AResponseContent: TStream), AURL - URL-, ;
AResponseContent - , ;
Function Trace (AURL: String): String,
AURI - URL-, .
.
1.1.3. PUT
PUT html- WEB-. IdHTTP :
Procedure Put(AURL: String; const ASource: TStream;
AResponseContent: TStream),
AURL - URL-. ;
ASource - , . ;
AResponseContent - , ;
Function Put (AURL: String; const ASource: TStream): String,
AURL - URL-, :
ASource - , . .
.
2.
2.1. HTTP-
, . 1-3.
.1
.2
. 3
, . 1.
1
,
IdHTTP1 | TldHTTP | HTTP- ( Indy Clients ) |
OpenDialog1 | TOpenDialog | ( Dialogs ) |
StatusBar1 | StatusBar | ( Win32 ) |
PageControl 1 | TPageControl | ( Win32 ). - GET, TRACE PUT |
Label1 | TLabel | URL. GET PageControl1 |
Label 2 | TLabel | HTTP-. GET, PageControl1 |
Edit1 | TEdit | URL. GET PageControl1 |
Memo1 | TMemo | . GET PageConlrol1. |
Button1 | TButton | GET (1 ). GET PageControl1 |
Button3 | TButton | GET (2 ). GET PageControl1 |
Label4 | TLabel | URL. TRACE PageControl1 |
Label5 | TLabel | . TRACE PageControl1 |
Edit2 | TEdit | URL. TRACE PageControl1 |
|
|
Memo2 | TMemo | . TRACE PageControl 1. |
Button2 | TButton | TRACE TRACE Page Control 1 |
Label3 | TLabel | . PUT PageControl 1 |
Label3 | TLabel | . PUT PageControl 1 |
Edit3 | TEdit | . PUT PageControl 1 |
Edit4 | TEdit | . PUT PageControl 1 |
Button4 | TButton | . PUT PageControl1 , |
Button5 | TButton | . PUT PageControl 1. , |
.
1) OnCreate Form 1 :
procedure Form1.FormCreate(Sender: TObjet):
begin
Edit1.Text:='http://myself/www/index.html';
Edit2.Text:='http://myself/www/index.html';
Edit4.Text:= 'http://myself/www/fl.html';
Memo1.Clear;
Statusbarl.SimplePanel:= True;
end;
URL , , SimpleText.
2) OnClick GET (1 ) :
procedure TForml.ButtonlClick(Sender: TObject);
Var s: TStringStream;
begin
try
s:=TStringStream.Create(");
IdHTTPI.Get(Edit1.Text,s);
s.Position:=0;
Memo1.Lines.LoadFromStream(s);
Statusbar1.SimpleText:='GET: OK';
except
on e: Exception do
begin
ShowMessage('Error:' + e.Message);
end; // on Exception
end;
end;
GET IdHTTP, GET . - s. , Memo1.Lines.LoadFromStream Memo1.
3) OnClick GET (2 ) :
procedure TForm1.Button3Click(Sender: TObject);
begin
try
If not IdHTTP1. Connected then IdHTTP1.Connect;
If IdHTTP1.Connected then
begin
StatusBar1.SimpleText:= 'Connect: OK';
try
memo1.Lines.Text:= IdHTTP1.Get(Edit1.Text);
StatusBar1.SimpleText:=' GET: OK';
except
StatusBarl.SimpleText:=' GET: ';
end;
end
else
StatusBarl.SimpleText:=' GET: Not connected';
except
StatusBarl.SimpleTexl:= ' GET:
';
end;
end;
GET IdHTTP, GET . memol.Lines.Text IdHTTP.Get
.4) OnClick TRACE :
procedure TForm1.Button2Click(Sender: TObject);
Var s: TStringStream;
begin
try
s:= TstringStream.Create(");
IdHTTP1.Trace(Edit2.Text,s);
s.Position:=0;
Memo2.Lines.LoadFromStream(s):
Statusbar1.SimpleText:= 'TRACE: OK';
except
Statusbarl.SimpleText:='TRACE: Error';
end;
end;
TRACE IdHTTP, TRACE . s. , Mmo2.Lines.LoadFromStream mo2.
5) OnClick :
procedure TForm1.Button4Click(Sender: TObject);
begin
If OpenDialogl.Execute then
Edit3.Text:= OpenDialogl.FileName:
end;
, .
6) OnClick :
procedure TForm1.Button5Click(Sender: TObject);
Var F: TFileStream;
s1: String;
begin
try
f:= TFileStream.Create(Edit3.Text. fmOpenRead);
s1:=IdHTTP1.Put(Edit4.Text, f);
Statusbar1.SimpleText:='PUT: OK';
f,Free;
except
Statusbar 1.SimpleText:= 'PUT: Error';
end;
end;
PUT IdHTTP, PUT .
1. TRACE .
2. PUT .
. Delphi /ep. . , , 2003. 640 .
1. IdHTTP:
2. HTTP ?
3. HTTP ?
4. , Memo, - ? s ?
19
WEB-
: WebBrowser Internet.
1.
Web- :
URL, Internet;
;
, .
Web- Delphi WebBrowser, Internet .
WebBrowser Navigate, , WebBrowser1.Navigate('D:\tests\file.html').
Navigate URL .
Web-, WebBrowser:
OnBeforeNavigate2 (- -WebBrowserlBeforeNavigat2) - . , : Navigate . URL , . Cancel, false, ;
OnProgressChange - (- WebBrowserlProgressChange). . LocationName WebBorowserl. Progress - ProgrssMax - . , . , Progress 1.
2.
WEB-, . 1 .
1) .
2) MainMenu Standart . , . 2.
3) CoolBar ( Win32 ). CoolBar ToolBar ( Win32 ).
. 1
. 2
4) true ShowCaptions, .
a) ToolBar - , . Caption.
b) ( ) Enabled false, .
) . ImageList ( Win32 ). ImageList . ToolBar Images ImageList1 ToolBar .
4) CoolBar ComboBox ( Standart ). URL HTML, .
5) Coolbar AutoSize ShowText true. . c.
6) Bands CoolBar , (ComboBox), Text .
7) StatusBar ( Win32 ). SimplePanel True. , .
8) WebBrowser ( Internet ). Align alClient, , HTML- . , . 1.
9) :
a) OnCreate Form1 :
procedure TForm1.FormCreate(Sender: TObject);
begin
// ComboBox 1
ComboBox1.Text:='http://myself/www/Main1.html';
WebBrowser1.Navigate(ComboBox1.Text);
end;
b) OnClick ComboBox :
procedure TForm1.ComboBox1Click(Sender: TObject);
begin
// Web- ,
// ComboBox
WebBrowser1.Navigate(ComboBox1.Text);
CoolBarl.Update;
end;
c) OnkeyDown ComboBox :
procedure TForml.ComboBox1KeyDown(Sender: TObject; var Key:
Word; Shift: TShiftState);
Begin
// Enter, Web-
If Key=VK_Return then
begin
WebBrowserl.Navigate(ComboBoxl.Text);
end;
end;
d) OnCiick :
procedure TForml.ToolButton1Click(Sender: TObject);
begin
//
ComboBox1.Text:= ComboBox1.Items[ComboBox1.itemIndex+1];
WebBrowserl.Navigate(ComboBox1.Text);
end;
e) OnCiick :
procedure TForm1.ToolButton2Cleck(Sender: TObject);
begin
//
ComboBox1.Text:= ComboBox1.Items[ComboBox1.ItemIndex-1];
WebBrowserl.Navigate(ComboBoxl.Text);
end;
f) OnClick :
procedure TForm1.ToolButton3Click(Sender: TObject);
begin
//
ComboBox1.Text:= 'http://myself/www/Main1.html';
WebBrowserl.Navigate(ComboBox1.Text);
end;
g) OnBeforeNavigate2 WebBrowserl :
procedure TFortn1.WebBrowser1BeforcNavigate2(Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
//
Var
Index: Integer;
begin
// ComboBox1
Index:= ComboBoxl.Items.IndexOf(URL);
If Index=1 then
begin
ComboBox1.Items.Insert(0,URL);
ComboBo1.ItemIndex:=0;
end
else ComboBoxl.ItemIndex:= Index;
//
If ComboBox1.ItemIndex>0
then ToolButton2.Enabled:= True
else ToolButton2.Enabled:= False;
If ComboBox1.ItemIndex<ComboBoxl.Items.Count-1
then ToolButton1.Enabled:= True
else ToolButton1.Enabled:= False;
end;
WebBrowserlBeforeNavigate2 IndexOf ComboBox 1 URL . IndexOf 1, . Insert ComboBox 1 ( 0) 0. , . . WebBrowserlBeforeNavigale2 TooButton2 () ToolButton1 () , ;
h) OnProgressChange WebBrowser1 :
procedure TForml.WebBrowser1ProgressChange(Sender: TObject; Progress,
ProgressMax: Integer);
//
begin
If Progress>0 then
Statusbar1.SimpleText: Format( %s: %d
%d, [WebBrowser1.LocationName,Progress div l024, Progressmax
div 1024]);
end;
WebBrowserlProgressChange WebBrowserl LocationName .
n) :
procedure TForm1.N10Click(Sender: TObject);
begin
//
If OpenDialogl.Execute then
begin
ComboBox1.Text:= OpenDialogl.FileName;
WebBrowser1.Navigate(ComboBox1.Text);
end;
end;
Text ComboBoxl.
12) , . 2.
1. . A. Delphi. . ., -, 2004. 976 .
2. . . Delphi . ., - , 2002. 1120 .
1. URL?
2. WebBrowser.
3. WebBrowser.
20