eName:string);
Rename:更改服务器上的文件名.
原型为:
procedure Rename(const ASourceFile:string;const ADestFile:string);
Size:获取文件大小信息.
原型为:
function Size(const AFileName:string):Integer;
begin
ftpcon.Enabled:=false;
//-----------------连接FTP服务器------------------//
with idftp do
begin
try
Host:=trim(edit1.Text); //FTP服务器IP地址
Username:=trim(edit2.Text); //用户名
Pass
word:=trim(edit3.Text); //密码
Connect; // 连接
DirectoryListBox.Items.Clear; // 清空目录以及文件信息
DebugListBox.Items.Clear; // 清空记录信息
// SaveFTPHostInfo(trim(CURDIR.Text), 'FTPHOST');
finally
if Connected then
begin
DisplayDir(trim(CURDIR.Text)); // 改变当前路径
FTPCon.Enabled:=false; // 连接按钮
FTPDisCon.Enabled:=True; // 断开按钮
end;
end;
end;
end;
断开按钮的代码:
begin
try
if IdFTP.Connected then // 判断客户端是否连着服务器
IdFTP.Abort;
if TransferrignData then // 判断客户端与服务器之间是否有数据传输
IdFTP.Quit;
finally
IdFTP.Disconnect; // 断开连接
FTPCon.Enabled:=true;
FTPDisCon.Enabled:=false;
end;
end;
TransferrignData变量全局变量里有定义的
连接按钮里的DisplayDir的过程如下:
procedure TFFTPClient.DisplayDir(DirName: String);
Var
LS: TStringList;
begin
LS := TStringList.Create;
try
IdFTP.ChangeDir(DirName);
IdFTP.TransferType:=ftASCII; // 编译不通过时 USES IdFTPCommon
CURDIR.Text:= IdFTP.RetrieveCurrentDir;
DirectoryListBox.Items.Clear;
IdFTP.List(LS); // 把IDFTP里的LIST与LS关联起来
DirectoryListBox.Items.Assign(LS); // 把DIRECTORYLISTBOX 与 LS 关联起来
if DirectoryListBox.Items.Count > 0 then
if AnsiPos('total', DirectoryListBox.Items[0]) > 0 then DirectoryListBox.Items.Delete(0
);
finally
LS.Free;
end;
end;
还有一个最重要的一段代码,就是listbox如何显示目录信息的
首先,把LISTBOX的STYLE的属性改成lbOwnerDrawFixed
再在ONDRAWITEM方法里添加如下代码:
procedure TFFTPClient.DirectoryListBoxDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
Var
R: TRect;
begin
//---------------------------------当选择一条记录时
if odSelected in State then
begin
DirectoryListBox.Canvas.Brush.Color := $00895F0A;
DirectoryListBox.Canvas.Font.Color := clWhite;
end
else
begin
DirectoryListBox.Canvas.Brush.Color := clWindow;
end;
//---------------------------------显示当前目录里的信息
if Assigned(IdFTP.DirectoryListing) and (IdFTP.DirectoryListing.Count>Index) then
begin
DirectoryListBox.Canvas.FillRect(Rect);
with IdFTP.DirectoryListing.Items[Index] do
begin
//------------------------//
DirectoryListBox.Canvas.TextOut(Rect.Left, Rect.Top, FileName); // 文件名
R := Rect;
R.Left := Rect.Left + HeaderControl1.Sections.Items[0].Width;
//------------------------//
R.Right := R.Left + HeaderControl1.Sections.Items[1].Width;
DirectoryListBox.Canvas.FillRect(R);
DirectoryListBox.Canvas.TextOut(R.Left, Rect.Top, IntToStr(Size)); // 文件大小
//------------------------//
R.Left := R.Right;
R.Right := R.Left + HeaderControl1.Sections.Items[2].Width;
DirectoryListBox.Canvas.FillRect(R);
if ItemType = ditDirectory then // 是文件夹类型 编译不通过时要USES IDFTPLIST
begin
DirectoryListBox.Canvas.TextOut(R.Left, Rect.Top, '文件夹');
end
else
begin
DirectoryListBox.Canvas.TextOu