Using a simple code, such as:
procedure TForm1.cxButton1Click(Sender: TObject);
begin
ftp.Host := 'domain';
ftp.Username := 'user';
ftp.Password := 'password';
ftp.Connect;
ftp.Put('C:\_Projects\testpicture.JPG');
ftp.Quit;
ftp.Disconnect;
end;
I’m getting the following results:
- Application freezes while uploading (ergo unable to see Progress Bar position).
- Uploaded file goes corrupted (corrupts anything more than a few bytes).
What on earth am I doing wrong?
Thank you.
The app freezes because Indy uses blocking operations. While the code is running, the main message loop is not running, so new messages are not being processed until
cxButton1Click()exits. To solve that, either place aTIdAntiFreezecomponent onto yourTForm, or else move theTIdFTPcode to a separate worker thread, and then useTIdSyncorTIdNotifyto update the UI safely when needed.The file will be “corrupted” if you are transferring it in ASCII mode instead of in binary mode. Make sure the
TIdFTP.TransferTypeproperty is set toftBinary. Indy 9 and earlier defaulted toftBinary, but Indy 10 defaults toftASCIIinstead (to match the FTP protocol specs).