为什么IDFTP放在线程里就连接不上服务器?
主代码如下:
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, StrUtils;
type
TFrm_Main = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
TFtp:array[1..5] of TThread;
function CreateDestFileUrl(dirs:TStringList;dirroot:string):string;
function UrlToFtpDir(Url:string):string;
function SplitString(const Source,ch:string):TStringList;
public
{ Public declarations }
end;
var
Frm_Main: TFrm_Main;
implementation
uses ThreadFTP;
{$R *.dfm}
function TFrm_Main.SplitString(const Source,ch:string):TStringList; //把一个字符串拆分成一个字符列表
var temp:String;
i:Integer;
begin
Result:=TStringList.Create;
try
if Source='' then exit;
temp:=Source;
i:=pos(ch,Source);
while i<>0 do
begin
Result.add(copy(temp,0,i-1));
Delete(temp,1,i);
i:=pos(ch,temp);
end;
Result.add(temp);
except
showmessage('分解字符出错'+Source);
end;
end;
function TFrm_Main.UrlToFtpDir(Url:string):string;
var i:integer;
begin
try
if Url='' then exit;
Url:=trim(Url);
i:=pos(':',Url);
Delete(Url,i,1);
Result:=AnsiReplaceText(Url,'\','/');
except
showmessage('转换出错');
end;
end;
function TFrm_Main.CreateDestFileUrl(dirs:TStringList;dirroot:string):string;
var i:integer;
DestFile:string;
begin
try
DestFile:=dirroot;
for i:=1 to dirs.Count-1 do
begin
DestFile:=DestFile+'\'+dirs.Strings[i];
end;
Result:=DestFile;
except
showmessage('获取目的文件路径出错');
end;
end;
procedure TFrm_Main.Button1Click(Sender: TObject);
var TIP,TUser,TPassword,TDfile,TDirroot,Url:string;
TPort:integer;
TDirs:TStringlist;
begin
TIP:='60.191.244.136';
TUser:='blues';
TPassword:='beginlove';
TPort:=210;
TDirroot:='E:';
Url:=UrlToFtpDir('G:\MOV_3\MOV\KB\SLEEPING_WITH_THE_DEAD\A.RM');
TDirs:=SplitString(Url,'/');
TDfile:=CreateDestFileUrl(TDirs,TDirroot);
TFtp[1]:=MyThreadFtp.Create(False,TIP,TPort,TUser,TPassword,TDirs,TDfile,TDirroot);
end;
end.