解决方案 »
- 【分享】D2010 自带的代码格式化
- 最近运气超好 嘿嘿~~
- 求delphi开发的类似“资源管理器”的程序原代码
- 这个结构在DELPHI中要怎么定义
- 求刘艺著的《delphi6企业级解决方案及应用剖析》附书光盘!先谢了!!
- 为什么不能实现?
- 怎样对stringgird进行隔行多选,解决马上给分!!!!
- WebSnap页面模块的Activate事件和Create事件的区别是?????????????????
- 在DBGrid控件,如何控制对每一行进行操作(如:我要将某行的字体设置一下)
- 为什么TQUERY并不一定将MS SQL7的错误返回给系统?
- 压缩传输组件 tcpserver tcpClient activeForm无法连接
- 【在线给分】如何修改字符串中某位的值
procedure TMainForm.ChageDir(DirName: String);
begin
try
SetFunctionButtons(false);
IdFTP1.ChangeDir(DirName); IdFTP1.TransferType := ftASCII; CurrentDirEdit.Text := IdFTP1.RetrieveCurrentDir; {Panel3.Caption := 'Current directory is: ' + IdFTP1.RetrieveCurrentDir +
' Remote system is ' + IdFTP1.SystemDesc;}
DirectoryListBox.Items.Clear;
IdFTP1.List(DirectoryListBox.Items);
finally
SetFunctionButtons(true);
end;
end;function GetNameFromDirLine(Line: String; Var IsDirectory: Boolean): String;
Var
i: Integer;
DosListing: Boolean;
begin
IsDirectory := Line[1] = 'd';
DosListing := false;
for i := 0 to 7 do begin
if (i = 2) and not IsDirectory then begin
IsDirectory := Copy(Line, 1, Pos(' ', Line) - 1) = '<DIR>';
if not IsDirectory then
DosListing := Line[1] in ['0'..'9']
else DosListing := true;
end;
Delete(Line, 1, Pos(' ', Line));
While Line[1] = ' ' do Delete(Line, 1, 1);
if DosListing and (i = 2) then break;
end;
Result := Line;
end;procedure TMainForm.DirectoryListBoxDblClick(Sender: TObject);
Var
Name, Line: String;
IsDirectory: Boolean;
begin
if not IdFTP1.Connected then exit;
Line := DirectoryListBox.Items[DirectoryListBox.ItemIndex];
Name := GetNameFromDirLine(Line, IsDirectory);
if IsDirectory then begin
// Change directory
SetFunctionButtons(false);
ChageDir(Name);
SetFunctionButtons(true);
end
else begin
try
SaveDialog1.FileName := Name;
if SaveDialog1.Execute then begin
SetFunctionButtons(false);
IdFTP1.TransferType := ftBinary;
BytesToTransfer := IdFTP1.Size(Name);
IdFTP1.Get(Name, SaveDialog1.FileName, true);
end;
finally
SetFunctionButtons(true);
end;
end;
end;procedure TMainForm.DeleteButtonClick(Sender: TObject);
Var
Name, Line: String;
IsDirectory: Boolean;
begin
if not IdFTP1.Connected then exit;
Line := DirectoryListBox.Items[DirectoryListBox.ItemIndex];
Name := GetNameFromDirLine(Line, IsDirectory);
if IsDirectory then try
SetFunctionButtons(false);
idftp1.RemoveDir(Name);
ChageDir(idftp1.RetrieveCurrentDir);
finally
end
else
try
SetFunctionButtons(false);
idftp1.Delete(Name);
ChageDir(idftp1.RetrieveCurrentDir);
finally
end;
end;procedure TMainForm.IdFTP1Disconnected(Sender: TObject);
begin
StatusBar1.Panels[1].Text := 'Disconnected.';
end;procedure TMainForm.AbortButtonClick(Sender: TObject);
begin
AbortTransfer := true;
end;procedure TMainForm.BackButtonClick(Sender: TObject);
begin
if not IdFTP1.Connected then exit;
try
ChageDir('..');
finally end;
end;
procedure TMainForm.IdFTP1Status(axSender: TObject; const axStatus: TIdStatus;
const asStatusText: String);
begin
DebugListBox.ItemIndex := DebugListBox.Items.Add(asStatusText);
StatusBar1.Panels[1].Text := asStatusText;
end;procedure TMainForm.TraceCheckBoxClick(Sender: TObject);
begin
IdLogDebug1.Active := TraceCheckBox.Checked;
DebugListBox.Visible := TraceCheckBox.Checked;
if DebugListBox.Visible then Splitter1.Top := DebugListBox.Top + 5;
end;procedure TMainForm.FormCreate(Sender: TObject);
begin
SetFunctionButtons(false);
IdLogDebug1.Active := true; FtpServerEdit.Text := GetHostInfo('FTPHOST'); ProgressBar1.Parent := StatusBar1;
ProgressBar1.Top := 2;
ProgressBar1.Left := 1;
{$IFDEF Linux}
ProgressBar1.Width := 142;
{$ENDIF}
end;procedure TMainForm.DirectoryListBoxClick(Sender: TObject);
Var
Line: String;
IsDirectory: Boolean;
begin
if not IdFTP1.Connected then exit;
Line := DirectoryListBox.Items[DirectoryListBox.ItemIndex];
GetNameFromDirLine(Line, IsDirectory);
if IsDirectory then DownloadButton.Caption := 'Change dir'
else DownloadButton.Caption := 'Download';
end;procedure TMainForm.IdFTP1Work(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
Var
S: String;
TotalTime: TDateTime;
H, M, Sec, MS: Word;
DLTime: Double;
begin
TotalTime := Now - STime;
DecodeTime(TotalTime, H, M, Sec, MS);
Sec := Sec + M * 60 + H * 3600;
DLTime := Sec + MS / 1000;
if DLTime > 0 then
AverageSpeed := {(AverageSpeed + }(AWorkCount / 1024) / DLTime{) / 2}; S := FormatFloat('0.00 KB/s', AverageSpeed);
case AWorkMode of
wmRead: StatusBar1.Panels[1].Text := 'Download speed ' + S;
wmWrite: StatusBar1.Panels[1].Text := 'Uploade speed ' + S;
end; if AbortTransfer then IdFTP1.Abort; ProgressBar1.Position := AWorkCount;
AbortTransfer := false;
end;procedure TMainForm.IdFTP1WorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
begin
TransferrignData := true;
AbortButton.Visible := true;
AbortTransfer := false;
STime := Now;
if AWorkCountMax > 0 then ProgressBar1.Max := AWorkCountMax
else ProgressBar1.Max := BytesToTransfer;
AverageSpeed := 0;
end;procedure TMainForm.IdFTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
begin
AbortButton.Visible := false;
StatusBar1.Panels[1].Text := 'Transfer complete.';
BytesToTransfer := 0;
TransferrignData := false;
ProgressBar1.Position := 0;
AverageSpeed := 0;
end;procedure TMainForm.UsePassiveClick(Sender: TObject);
begin
IdFTP1.Passive := UsePassive.Checked;
end;procedure TMainForm.ChDirButtonClick(Sender: TObject);
begin
SetFunctionButtons(false);
ChageDir(CurrentDirEdit.Text);
SetFunctionButtons(true);
end;procedure TMainForm.CreateDirButtonClick(Sender: TObject);
Var
S: String;
begin
S := InputBox('Make new directory', 'Name', '');
if S <> '' then
try
SetFunctionButtons(false);
IdFTP1.MakeDir(S);
ChageDir(CurrentDirEdit.Text);
finally
SetFunctionButtons(true);
end;
end;procedure TMainForm.SaveFTPHostInfo(Datatext, header: String);
var
ServerIni: TIniFile;
begin
ServerIni := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'FtpHost.ini');
ServerIni.WriteString('Server', header, Datatext);
ServerIni.UpdateFile;
ServerIni.Free;
end;function TMainForm.GetHostInfo(header: String): String;
var
ServerName: String;
ServerIni: TIniFile;
begin
ServerIni := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'FtpHost.ini');
ServerName := ServerIni.ReadString('Server', header, header); ServerIni.Free;
result := ServerName;
end;
end.
不胜感激 我想加分 可是我不知道怎么修改问题点数~