1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
| procedure TForm7.ConnectButtonClick(Sender: TObject);
begin
ConnectButton.Enabled:=false;
idFtp1.Passive := True;
if IdFTP1.Connected
then
try
if TransferrignData
then IdFTP1.Abort;
IdFTP1.Quit;
finally
CurrentDirEdit.Text:='/';
DirectoryListBox.Items.Clear;
ConnectButton.Caption:='Подключиться';
ConnectButton.Enabled:=true;
ConnectButton.Default:=true;
end
else
with IdFTP1 do try
Username:=UserIDEdit.Text;
Password:=PasswordEdit.Text;
Host:=FtpServerEdit.Text;
Connect;
Self.ChageDir(CurrentDirEdit.Text);
finally
ConnectButton.Enabled:=true;
if Connected
then
begin
ConnectButton.Caption:='Отключиться';
ConnectButton.Default:=false;
end;
end;
end;
procedure TForm7.UploadButtonClick(Sender: TObject);
begin
if IdFTP1.Connected
then
begin
if UploadOpenDialog1.Execute
then
try
IdFTP1.TransferType:=ftBinary;
IdFTP1.Put(UploadOpenDialog1.FileName, ExtractFileName(UploadOpenDialog1.FileName));
ChageDir(idftp1.RetrieveCurrentDir);
finally
end;
end;
end;
procedure TForm7.ChageDir(DirName: string);
var
LS: TStringList;
begin
LS:=TStringList.Create;
try
IdFTP1.ChangeDir(DirName);
IdFTP1.TransferType:=ftASCII;
CurrentDirEdit.Text:=IdFTP1.RetrieveCurrentDir;
DirectoryListBox.Items.Clear;
IdFTP1.List(LS);
DirectoryListBox.Items.Assign(LS);
if DirectoryListBox.Items.Count>0
then
if AnsiPos('total', DirectoryListBox.Items[0])>0
then DirectoryListBox.Items.Delete(0);
finally
LS.Free;
end;
end;
procedure TForm7.DirectoryListBoxDblClick(Sender: TObject);
var
Name: string;
begin
if not IdFTP1.Connected
then Exit;
Name:=IdFTP1.DirectoryListing.Items[DirectoryListBox.ItemIndex].FileName;
if IdFTP1.DirectoryListing.Items[DirectoryListBox.ItemIndex].ItemType=ditDirectory
then
begin
// Change directory
ChageDir(Name);
end
else
begin
try
SaveDialog1.FileName:=Name;
if SaveDialog1.Execute
then
begin
IdFTP1.TransferType:=ftBinary;
BytesToTransfer:=IdFTP1.Size(Name);
if FileExists(Name)
then
begin
case MessageDlg('Файл существует. Хотите перезаписать его?',
mtConfirmation, mbYesNoCancel, 0) of
mrYes:
begin
BytesToTransfer:=BytesToTransfer-FileSizeByName(Name);
IdFTP1.Get(Name, SaveDialog1.FileName, false, true);
end;
mrNo:
begin
IdFTP1.Get(Name, SaveDialog1.FileName, true);
end;
mrCancel:
begin
Exit;
end;
end;
end
else IdFTP1.Get(Name, SaveDialog1.FileName, false);
end;
finally
end;
end;
end;
procedure TForm7.DeleteButtonClick(Sender: TObject);
var
Name: string;
begin
if not IdFTP1.Connected
then Exit;
Name:=IdFTP1.DirectoryListing.Items[DirectoryListBox.ItemIndex].FileName;
if IdFTP1.DirectoryListing.Items[DirectoryListBox.ItemIndex].ItemType=ditDirectory
then
try
idftp1.RemoveDir(Name);
ChageDir(idftp1.RetrieveCurrentDir);
finally
end
else
try
idftp1.Delete(Name);
ChageDir(idftp1.RetrieveCurrentDir);
finally
end;
end;
procedure TForm7.IdFTP1Disconnected(Sender: TObject);
begin
StatusBar1.Panels[1].Text:='Отключен';
end;
procedure TForm7.AbortButtonClick(Sender: TObject);
begin
AbortTransfer:=true;
end;
procedure TForm7.BackButtonClick(Sender: TObject);
begin
if not IdFTP1.Connected
then Exit;
try
ChageDir('..');
finally
end;
end;
procedure TForm7.IdFTP1Status(axSender: TObject; const axStatus: TIdStatus;
const asStatusText: string);
begin
DebugListBox.ItemIndex:=DebugListBox.Items.Add(asStatusText);
StatusBar1.Panels[1].Text:=asStatusText;
end;
procedure TForm7.FormCreate(Sender: TObject);
begin
IdFtp1.Intercept:=IdLogEvent1;
end;
procedure TForm7.DirectoryListBoxClick(Sender: TObject);
begin
if not IdFTP1.Connected
then Exit;
if DirectoryListBox.ItemIndex>-1
then
begin
if IdFTP1.DirectoryListing.Items[DirectoryListBox.ItemIndex].ItemType=ditDirectory
then DownloadButton.Caption:='Далее'
else DownloadButton.Caption:='Скачать';
end;
end;
procedure TForm7.IdFTP1Work(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
var
S: string;
TotalTime: TDateTime;
// RemainingTime: 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};
if AverageSpeed>0
then
begin
Sec:=Trunc(((ProgressBar1.Max-AWorkCount)/1024/AverageSpeed));
S:=Format('%2d:%2d:%2d', [Sec div 3600, (Sec div 60) mod 60, Sec mod 60]);
S:='Осталось времени: '+S;
end
else S:='';
//
S:=FormatFloat('0.00 Кб/сек', AverageSpeed)+'; '+S;
case AWorkMode of
wmRead: StatusBar1.Panels[1].Text:='Скорость скачивания: '+S;
wmWrite: StatusBar1.Panels[1].Text:='Скорость загрузки: '+S;
end;
if AbortTransfer
then IdFTP1.Abort;
ProgressBar1.Position:=AWorkCount;
AbortTransfer:=false;
end;
procedure TForm7.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 TForm7.IdFTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
begin
AbortButton.Visible:=false;
StatusBar1.Panels[1].Text:='Передача завершена';
BytesToTransfer:=0;
TransferrignData:=false;
ProgressBar1.Position:=0;
AverageSpeed:=0;
end;
procedure TForm7.UsePassiveClick(Sender: TObject);
begin
IdFTP1.Passive:=UsePassive.Checked;
end;
procedure TForm7.ChDirButtonClick(Sender: TObject);
begin
ChageDir(CurrentDirEdit.Text);
end;
procedure TForm7.CreateDirButtonClick(Sender: TObject);
var
S: string;
begin
S:=InputBox('Новая директория', 'Имя', '');
if S<>''
then
try
IdFTP1.MakeDir(S);
ChageDir(CurrentDirEdit.Text);
finally
end;
end;
procedure TForm7.PutToDebugLog(Operation, S1: String);
var
S: string;
begin
while Length(S1)>0 do
begin
if Pos(#13, S1)>0
then
begin
S:=Copy(S1, 1, Pos(#13, S1)-1);
Delete(S1, 1, Pos(#13, S1));
if S1[1]=#10
then Delete(S1, 1, 1);
end
else S := S1;
DebugListBox.ItemIndex := DebugListBox.Items.Add(Operation + S);
end;
end;
procedure TForm7.IdLogEvent1Received(ASender: TComponent; const AText,
AData: string);
begin
PutToDebugLog('<<- ', AData);
end;
procedure TForm7.IdLogEvent1Sent(ASender: TComponent; const AText,
AData: string);
begin
PutToDebugLog('->> ', AData);
end;
{$IFDEF Linux}
procedure TForm7.DebugListBoxDrawItem(Sender: TObject; Index: Integer;
Rect: TRect; State: TOwnerDrawState; var Handled: Boolean);
{$ELSE}
procedure TForm7.DebugListBoxDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
{$ENDIF}
begin
if Pos('>>', DebugListBox.Items[index])>1
then DebugListBox.Canvas.Font.Color:=clRed
else DebugListBox.Canvas.Font.Color:=clBlue;
if odSelected in State
then
begin
DebugListBox.Canvas.Brush.Color:=$00895F0A;
DebugListBox.Canvas.Font.Color:=clWhite;
end
else DebugListBox.Canvas.Brush.Color := clWindow;
DebugListBox.Canvas.FillRect(Rect);
DebugListBox.Canvas.TextOut(Rect.Left, Rect.Top, DebugListBox.Items[index]);
end;
{$IFDEF Linux}
procedure TForm7.DirectoryListBoxDrawItem(Sender: TObject; Index: Integer;
Rect: TRect; State: TOwnerDrawState; var Handled: Boolean);
{$ELSE}
procedure TForm7.DirectoryListBoxDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
{$ENDIF}
var
R: TRect;
begin
if odSelected in State
then
begin
DirectoryListBox.Canvas.Brush.Color:=$00895F0A;
DirectoryListBox.Canvas.Font.Color:=clWhite;
end
else DirectoryListBox.Canvas.Brush.Color:=clWindow;
//
if Assigned(IdFTP1.DirectoryListing) and (IdFTP1.DirectoryListing.Count>Index)
then
begin
DirectoryListBox.Canvas.FillRect(Rect);
with IdFTP1.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 DirectoryListBox.Canvas.TextOut(R.Left, Rect.Top, 'Directory')
else DirectoryListBox.Canvas.TextOut(R.Left, Rect.Top, 'File');
R.Left:=R.Right;
R.Right:=R.Left+HeaderControl1.Sections.Items[3].Width;
DirectoryListBox.Canvas.FillRect(R);
DirectoryListBox.Canvas.TextOut(R.Left, Rect.Top, FormatDateTime('mm/dd/yyyy hh:mm', ModifiedDate));
R.Left:=R.Right;
R.Right:=R.Left+HeaderControl1.Sections.Items[4].Width;
DirectoryListBox.Canvas.FillRect(R);
DirectoryListBox.Canvas.TextOut(R.Left, Rect.Top, GroupName);
end;
end;
end;
{$IFDEF Linux}
procedure TForm7.HeaderControl1SectionResize(HeaderControl: TCustomHeaderControl;
Section: TCustomHeaderSection);
{$ELSE}
procedure TForm7.HeaderControl1SectionResize(HeaderControl: THeaderControl; Section: THeaderSection);
{$ENDIF}
begin
DirectoryListBox.Repaint;
end;
procedure TForm7.DebugListBoxClick(Sender: TObject);
begin
end;
procedure TForm7.FtpServerEditChange(Sender: TObject);
begin
end;
procedure TForm7.UserIDEditChange(Sender: TObject);
begin
end;
procedure TForm7.PasswordEditChange(Sender: TObject);
begin
end;
procedure TForm7.CurrentDirEditChange(Sender: TObject);
begin
end;
procedure TForm7.Label5Click(Sender: TObject);
begin
end;
procedure TForm7.HeaderControl1SectionTrack(HeaderControl: THeaderControl;
Section: THeaderSection; Width: Integer; State: TSectionTrackState);
begin
end;
procedure TForm7.N4Click(Sender: TObject);
begin
close;
end;
procedure TForm7.N6Click(Sender: TObject);
begin
winExec('hh Helper.chm', SW_RESTORE);
end;
procedure TForm7.N9Click(Sender: TObject);
begin
Form8.Show;
end;
procedure TForm7.IdFTP1AfterClientLogin(Sender: TObject);
begin
end;
procedure TForm7.IdFTP2AfterClientLogin(Sender: TObject);
begin
end;
end. |