?? ftptst1.pas
字號:
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Author: Fran鏾is PIETTE
Creation: Aug 1997
Version: 2.24
Object: Demo for TFtpClient object (RFC 959 implementation)
It is a graphical FTP client program
Compatible with Delphi 1, 2, 3, 4 and 5
EMail: francois.piette@pophost.eunet.be francois.piette@swing.be
francois.piette@rtfm.be http://www.rtfm.be/fpiette
Support: Use the mailing list twsocket@rtfm.be See website for details.
Legal issues: Copyright (C) 1997, 1998, 1999 by Fran鏾is PIETTE
Rue de Grady 24, 4053 Embourg, Belgium. Fax: +32-4-365.74.56
<francois.piette@pophost.eunet.be>
This software is provided 'as-is', without any express or
implied warranty. In no event will the author be held liable
for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it
and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented,
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
4. You must register this software by sending a picture postcard
to the author. Use a nice stamp and mention your name, street
address, EMail address and any comment you like to say.
Updates:
Sep 13, 97 Added directory functions. Added button to show how to makes
several transferts in one session
Sep 27, 97 Change identifiers names to be more standard with other sources
Jan 10, 98 Saved edit boxes content to an IniFile, added FileSize, Quote
and RestartGet commands
Jan 25, 1998 Completely rewritten for new component version (Asynchronous)
Feb 02, 1998 V2.17 Added a checkbox to run the synchronous or asynchronous
version of the component methods.
Feb 15, 1998 V2.18 Removed useless wait unit from the use clause.
Added display of winsock information at startup.
Feb 22, 1998 V2.19 Added Append and AppendFile commands
Aug 21, 1998 V2.20 Added a comment in OnProgress event handler to warn user
about CPU usage.
Dec 22, 1998 V2.21 Replaced DisplayFlag by DysplayFileFlag.
Oct 19, 1999 V2.22 Correctly display Winsock version
Nov 24, 1999 V2.23 Added Restart Put and NoAutoResumeAt.
Jan 28, 2000 V2.24 Added code to OnProgress event handler to update screen
only once per second. This solve problem on fast LAN.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
unit Ftptst1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, FtpCli, StdCtrls, IniFiles, ExtCtrls, WinSock, WSocket;
const
FTPTstVersion = 224;
type
TSyncCmd = function : Boolean of object;
TAsyncCmd = procedure of object;
TFtpReceiveForm = class(TForm)
DisplayMemo: TMemo;
FtpClient1: TFtpClient;
Panel1: TPanel;
ExitButton: TButton;
OpenAsyncButton: TButton;
QuitAsyncButton: TButton;
CwdAsyncButton: TButton;
UserAsyncButton: TButton;
PassAsyncButton: TButton;
ConnectAsyncButton: TButton;
GetAsyncButton: TButton;
ReceiveAsyncButton: TButton;
AbortAsyncButton: TButton;
DirAsyncButton: TButton;
DirectoryAsyncButton: TButton;
LsAsyncButton: TButton;
ListAsyncButton: TButton;
SystAsyncButton: TButton;
SystemAsyncButton: TButton;
FileSizeAsyncButton: TButton;
SizeAsyncButton: TButton;
MkdAsyncButton: TButton;
MkdirAsyncButton: TButton;
RmdAsyncButton: TButton;
RmdirAsyncButton: TButton;
RenAsyncButton: TButton;
RenameAsyncButton: TButton;
DeleAsyncButton: TButton;
DeleteAsyncButton: TButton;
PwdAsyncButton: TButton;
QuoteAsyncButton: TButton;
DoQuoteAsyncButton: TButton;
PutAsyncButton: TButton;
TransmitAsyncButton: TButton;
TypeSetAsyncButton: TButton;
RestGetAsyncButton: TButton;
RestartGetAsyncButton: TButton;
CDupAsyncButton: TButton;
Panel2: TPanel;
Label1: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label2: TLabel;
Label6: TLabel;
HostNameEdit: TEdit;
HostFileEdit: TEdit;
UserNameEdit: TEdit;
PassWordEdit: TEdit;
cbDisplay: TCheckBox;
LocalFileEdit: TEdit;
cbBinary: TCheckBox;
HostDirEdit: TEdit;
PortEdit: TEdit;
InfoLabel: TLabel;
StateLabel: TLabel;
ClearButton: TButton;
SyncCheckBox: TCheckBox;
AppendFileAsyncButton: TButton;
AppendAsyncButton: TButton;
PassiveCheckBox: TCheckBox;
Button1: TButton;
RestPutAsyncButton: TButton;
RestartPutAsyncButton: TButton;
ResumeAtEdit: TEdit;
Label7: TLabel;
NoAutoResumeAtCheckBox: TCheckBox;
procedure ExitButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Display(Sender: TObject; var Msg : String);
procedure FtpClient1Progress(Sender: TObject; Count: Longint;
var Abort: Boolean);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure OpenAsyncButtonClick(Sender: TObject);
procedure FtpClient1RequestDone(Sender: TObject; RqType: TFtpRequest;
Error: Word);
procedure FtpClient1SessionConnected(Sender: TObject; Error: Word);
procedure FtpClient1SessionClosed(Sender: TObject; Error: Word);
procedure QuitAsyncButtonClick(Sender: TObject);
procedure CwdAsyncButtonClick(Sender: TObject);
procedure UserAsyncButtonClick(Sender: TObject);
procedure PassAsyncButtonClick(Sender: TObject);
procedure ConnectAsyncButtonClick(Sender: TObject);
procedure FtpClient1StateChange(Sender: TObject);
procedure GetAsyncButtonClick(Sender: TObject);
procedure ReceiveAsyncButtonClick(Sender: TObject);
procedure AbortAsyncButtonClick(Sender: TObject);
procedure DirAsyncButtonClick(Sender: TObject);
procedure DirectoryAsyncButtonClick(Sender: TObject);
procedure LsAsyncButtonClick(Sender: TObject);
procedure ListAsyncButtonClick(Sender: TObject);
procedure SystAsyncButtonClick(Sender: TObject);
procedure SystemAsyncButtonClick(Sender: TObject);
procedure FileSizeAsyncButtonClick(Sender: TObject);
procedure SizeAsyncButtonClick(Sender: TObject);
procedure MkdAsyncButtonClick(Sender: TObject);
procedure MkdirAsyncButtonClick(Sender: TObject);
procedure RmdAsyncButtonClick(Sender: TObject);
procedure RmdirAsyncButtonClick(Sender: TObject);
procedure RenAsyncButtonClick(Sender: TObject);
procedure RenameAsyncButtonClick(Sender: TObject);
procedure DeleAsyncButtonClick(Sender: TObject);
procedure DeleteAsyncButtonClick(Sender: TObject);
procedure PwdAsyncButtonClick(Sender: TObject);
procedure QuoteAsyncButtonClick(Sender: TObject);
procedure DoQuoteAsyncButtonClick(Sender: TObject);
procedure PutAsyncButtonClick(Sender: TObject);
procedure TransmitAsyncButtonClick(Sender: TObject);
procedure TypeSetAsyncButtonClick(Sender: TObject);
procedure RestGetAsyncButtonClick(Sender: TObject);
procedure RestartGetAsyncButtonClick(Sender: TObject);
procedure CDupAsyncButtonClick(Sender: TObject);
procedure ClearButtonClick(Sender: TObject);
procedure AppendAsyncButtonClick(Sender: TObject);
procedure AppendFileAsyncButtonClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure RestPutAsyncButtonClick(Sender: TObject);
procedure RestartPutAsyncButtonClick(Sender: TObject);
private
FIniFileName : String;
FInitialized : Boolean;
FLastProgress : DWORD;
FProgressCount : LongInt;
procedure DisplayFile(FileName : String);
procedure ExecuteCmd(SyncCmd : TSyncCmd; ASyncCmd : TAsyncCmd);
public
end;
const
TEMP_FILE_NAME = 'FTPDIR.TXT';
var
FtpReceiveForm: TFtpReceiveForm;
implementation
uses
FtpTst2;
{$R *.DFM}
const
SectionData = 'Data';
KeyHostName = 'HostName';
KeyUserName = 'UserName';
KeyPassWord = 'PassWord';
KeyHostDir = 'HostDir';
KeyPort = 'Port';
KeyHostFile = 'HostFile';
KeyLocalFile = 'LocalFile';
KeyResumeAt = 'ResumeAt';
SectionWindow = 'Window';
KeyTop = 'Top';
KeyLeft = 'Left';
KeyWidth = 'Width';
KeyHeight = 'Height';
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{$IFNDEF VER80 }
{ To debug event driven programs, it is often handy to just use writeln to }
{ write debug messages to the console. To get a console, just ask the }
{ linker to build a console mode application. Then you'll get the default }
{ console. The function below will make it the size you like... }
procedure BigConsole(nCols, nLines : Integer);
var
sc : TCoord;
N : DWord;
begin
if not IsConsole then
Exit;
sc.x := nCols;
sc.y := nLines;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), sc);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
BACKGROUND_BLUE or BACKGROUND_GREEN or
BACKGROUND_RED or BACKGROUND_INTENSITY);
sc.x := 0;
sc.y := 0;
FillConsoleOutputAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
BACKGROUND_BLUE or BACKGROUND_GREEN or
BACKGROUND_RED or BACKGROUND_INTENSITY,
nCols * nLines, sc, N);
end;
{$ENDIF}
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpReceiveForm.FormCreate(Sender: TObject);
begin
{$IFNDEF VER80}
BigConsole(80, 100);
{$ENDIF}
DisplayMemo.Clear;
InfoLabel.Caption := '';
StateLabel.Caption := '';
FIniFileName := LowerCase(ExtractFileName(Application.ExeName));
FIniFileName := Copy(FIniFileName, 1, Length(FIniFileName) - 3) + 'ini';
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpReceiveForm.FormShow(Sender: TObject);
var
IniFile : TIniFile;
Data : TWSAData;
begin
if not FInitialized then begin
FInitialized := TRUE;
IniFile := TIniFile.Create(FIniFileName);
HostNameEdit.Text := IniFile.ReadString(SectionData, KeyHostName,
'ftp.simtel.net');
PortEdit.Text := IniFile.ReadString(SectionData, KeyPort,
'ftp');
UserNameEdit.Text := IniFile.ReadString(SectionData, KeyUserName,
'anonymous');
PassWordEdit.Text := IniFile.ReadString(SectionData, KeyPassWord,
'your.name@your.company.com');
HostDirEdit.Text := IniFile.ReadString(SectionData, KeyHostDir,
'/pub/simtelnet');
HostFileEdit.Text := IniFile.ReadString(SectionData, KeyHostFile,
'index.html');
LocalFileEdit.Text := IniFile.ReadString(SectionData, KeyLocalFile,
'c:\temp\index.htm');
ResumeAtEdit.Text := IniFile.ReadString(SectionData, KeyResumeAt,
'0');
Width := IniFile.ReadInteger(SectionWindow, KeyWidth, Width);
Height := IniFile.ReadInteger(SectionWindow, KeyHeight, Height);
Top := IniFile.ReadInteger(SectionWindow, KeyTop, (Screen.Height - Height) div 2);
Left := IniFile.ReadInteger(SectionWindow, KeyLeft, (Screen.Width - Width) div 2);
IniFile.Free;
{ Display winsock info }
Data := WinsockInfo;
DisplayMemo.Lines.Add('Winsock version ' +
IntToStr(LOBYTE(Data.wHighVersion)) + '.' +
IntToStr(HIBYTE(Data.wHighVersion)));
DisplayMemo.Lines.Add(StrPas(Data.szDescription));
DisplayMemo.Lines.Add(StrPas(Data.szSystemStatus));
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpReceiveForm.FormClose(Sender: TObject;
var Action: TCloseAction);
var
IniFile : TIniFile;
begin
IniFile := TIniFile.Create(FIniFileName);
IniFile.WriteString(SectionData, KeyHostName, HostNameEdit.Text);
IniFile.WriteString(SectionData, KeyPort, PortEdit.Text);
IniFile.WriteString(SectionData, KeyUserName, UserNameEdit.Text);
IniFile.WriteString(SectionData, KeyPassWord, PassWordEdit.Text);
IniFile.WriteString(SectionData, KeyHostDir, HostDirEdit.Text);
IniFile.WriteString(SectionData, KeyHostFile, HostFileEdit.Text);
IniFile.WriteString(SectionData, KeyLocalFile, LocalFileEdit.Text);
IniFile.WriteString(SectionData, KeyResumeAt, ResumeAtEdit.Text);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -