Indy FTP Failed to upload

Using simple code, for example:

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 get the following results:

  • The application freezes at loading (ergo cannot see the position of the Progress Bar).
  • The downloaded file is corrupt (corrupts something more than a few bytes).

What am I doing wrong?

Thanks.

+4
source share
1 answer

Application freezes because Indy uses blocking operations. While the code is running, the main message loop is not running, so new messages are not processed until cxButton1Click() exits. To solve this problem, put the TIdAntiFreeze component on your TForm or move the TIdFTP code to a separate workflow, and then use TIdSync or TIdNotify to safely update the user interface if necessary.

The file will be “damaged” if you transfer it in ASCII mode, and not in binary mode. Verify that the TIdFTP.TransferType property TIdFTP.TransferType set to ftBinary . Indy 9 and earlier were ftBinary by default, but Indy 10 by default instead of ftASCII (to meet FTP protocol specifications).

+12
source

Source: https://habr.com/ru/post/1383751/


All Articles