P
pengxuan7591
Unregistered / Unconfirmed
GUEST, unregistred user!
自己写了一个多线程上传的例子,但是在上传过程中偶尔会出现问题:10个文件只上传了7个或8个,或有时候就能全部上传.
unit U_FTPClient;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdFTP, ExtCtrls, Grids, DBGrids, DB, ADODB, StdCtrls, IdIntercept,
IdLogBase, IdLogEvent;
type
TMyFirstThread = class(TThread)
private
id:string;
filename:string;
protected
procedure Execute;override;
end;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
Memo1: TMemo;
IdLogEvent1: TIdLogEvent;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i:integer=1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var Thread1:TMyFirstThread;
begin
ADOQuery1.First;
while not ADOQuery1.Eof do
begin
Thread1:=TMyFirstThread.Create(true);
Thread1.id:=ADOQuery1.FieldByName('F_ID').AsString;
Thread1.filename:=ADOQuery1.FieldByName('F_WJ').AsString;
Thread1.Resume;
ADOQuery1.Next;
end;
end;
{ TMyFirstThread }
procedure TMyFirstThread.Execute;
var IdFTP:TIdFTP;
begin
IdFTP:=TIdFTP.Create(nil);
try
try
IdFTP.Host:='10.113.58.253';
IdFTP.Port:=21;
IdFTP.Username:='aa';
IdFTP.Password:='123';
IdFTP.Connect;
IdFTP.List(nil);
Form1.Memo1.Lines.Add(IntToStr(Form1.Memo1.Lines.Count+1)+' '+ExtractFileName(Self.filename)+' '+'准备上传!');
IdFTP.Put(Self.filename,ExtractFileName(Self.filename));
Form1.Memo1.Lines.Add(IntToStr(Form1.Memo1.Lines.Count+1)+' '+ExtractFileName(Self.filename)+' '+'上传成功!');
except
Form1.Memo1.Lines.Add(Self.id+ExtractFileName(Self.filename)+'上传失败!');
end;
finally
IdFTP.Free;
end;
end;
end.
哪位朋友帮忙看看/谢谢
unit U_FTPClient;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdFTP, ExtCtrls, Grids, DBGrids, DB, ADODB, StdCtrls, IdIntercept,
IdLogBase, IdLogEvent;
type
TMyFirstThread = class(TThread)
private
id:string;
filename:string;
protected
procedure Execute;override;
end;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
Memo1: TMemo;
IdLogEvent1: TIdLogEvent;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i:integer=1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var Thread1:TMyFirstThread;
begin
ADOQuery1.First;
while not ADOQuery1.Eof do
begin
Thread1:=TMyFirstThread.Create(true);
Thread1.id:=ADOQuery1.FieldByName('F_ID').AsString;
Thread1.filename:=ADOQuery1.FieldByName('F_WJ').AsString;
Thread1.Resume;
ADOQuery1.Next;
end;
end;
{ TMyFirstThread }
procedure TMyFirstThread.Execute;
var IdFTP:TIdFTP;
begin
IdFTP:=TIdFTP.Create(nil);
try
try
IdFTP.Host:='10.113.58.253';
IdFTP.Port:=21;
IdFTP.Username:='aa';
IdFTP.Password:='123';
IdFTP.Connect;
IdFTP.List(nil);
Form1.Memo1.Lines.Add(IntToStr(Form1.Memo1.Lines.Count+1)+' '+ExtractFileName(Self.filename)+' '+'准备上传!');
IdFTP.Put(Self.filename,ExtractFileName(Self.filename));
Form1.Memo1.Lines.Add(IntToStr(Form1.Memo1.Lines.Count+1)+' '+ExtractFileName(Self.filename)+' '+'上传成功!');
except
Form1.Memo1.Lines.Add(Self.id+ExtractFileName(Self.filename)+'上传失败!');
end;
finally
IdFTP.Free;
end;
end;
end.
哪位朋友帮忙看看/谢谢