I have an FTP downloader project that uses a form created at runtime to start uploading to multiple FTP servers (using Indy), my problem is this (and I really need your help).
On the form, I add the IdFTP component + download button + public properties named FTPSrvAdrs and SrcFile + TrgFolder as follows:
type TFtpUploader = class(TForm) IdFTP: TIdFTP; StartUpload:TButton; UploadProgress:TProgressBar; procedure StartUploadClick(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private FFtpSrvAdrs:String; FSrcFile:String; FTargetFtpFld:String; Procedure StartMyUpload(); procedure SetFtpAdrs(const value:string); procedure SetSrcFile(const value:string); procedure SetTargetFtpFld(const value:string); { Private declarations } public { Public declarations } property FtpAdrs:string read FFtpSrvAdrs write SetFtpAdrs; property SourceFile:string read FSrcFile write SetSrcFile; property TargetFtpFld:string read FTargetFtpFld write SetTargetFtpFld; end; var FtpUploader: TFtpUploader; implementation procedure TFtpUploader.StartUploadClick(Sender: TObject); begin StartMyUpload(); end; procedure TFtpUploader.SetFtpAdrs(const value: string); begin FFtpSrvAdrs:=value; end; procedure TFtpUploader.SetSrcFile(const value: string); begin FSrcFile:=value; end; procedure TFtpUploader.SetTargetFtpFld(const value: string); begin FTargetFtpFld:=value; end; procedure TFtpUploader.StartMyUpload; var FtpUpStream: TFileStream; begin ftpUpStream:= TFileStream.create(FSrcFile, fmopenread) try with IdFTP do begin Host:= FFtpSrvAdrs; Username:='MyUserName'; Password:='MyPassword'; end; IdFTP.Connect(true, 1200) IdFTP.Passive:= true; IdFTP.ChangeDir(FTargetFtpFld) IdFTP.Put(ftpUpStream,FSrcFile, false); finally ftpUpStream.Free; end; end; procedure TFtpUploader.FormClose(Sender: TObject; var Action: TCloseAction); begin Action:=caFree; end;
This form will be created in RunTime (4 times = 4 buttons will be launched separately, like this way:
in the main form, I have this procedure:
Procedure MainForm.UploadTo(FTPSrv,SrcFile,FtpTargetFld:String); var FUploadFrm:TFtpUploader; begin FUploadFrm:=TFtpUploader.Create(nil); if assigned(FUploadFrm) then begin FUploadFrm.FtpAdrs:=FTPSrv; FUploadFrm.SourceFile:=SrcFile; FUploadFrm.TargetFtpFld:=FtpTargetFld; FUploadFrm.Show; end; end; procedure MainForm.Button1Click(Sender: TObject); begin UploadTo('MyFtpSrv_1','MySrcFile_1','MyFtpTargetFld_1'); end; procedure MainForm.Button2Click(Sender: TObject); begin UploadTo('MyFtpSrv_2','MySrcFile_2','MyFtpTargetFld_2'); end; // same with other 2 buttons
The FtpUploader formats are created / opened (4 instances), ISSUE IS, when I click the StartUpload button, the FTP upload process does not start in all four of these instances, but I must wait for each upload process to be completed (completed) and the other to start automatically , that is, not all boot processes start at the same time.
Thanks.
source share