BUG on TIdFTP (TransferType is not set to Binary) - Easy to fix

Giganews Newsgroups
Subject: BUG on TIdFTP (TransferType is not set to Binary) - Easy to fix
Posted by:  diegoqueiroz (garoto.bur…@gmail.com)
Date: Fri, 28 Dec 2007

Hello guys.

I found a bug on TIdFTP. I'm using the last version of Indy 10.

All files are sent via ASCII Transfer Type Mode when the AutoLogin is set to False.
This is due a incorrect implementation of Connect method, where the SendTransferType protected method is called inside the "if Autologin..." block.
I won't say so much. I'll show the code.

Look to this code:

var
  MyFTP: TIdFTP;
begin
  MyFTP := TIdFTP.Create;

  try
    { Set the Server properties correctly }
    MyFTP.Host := 'myhost';
    MyFTP.Username := 'myuser';
    MyFTP.Password := 'mypassword';

    { Set the type of transfer to Binary }
    MyFTP.TransferType := ftBinary;
    // Pay attention to this: I'm explicit setting the Transfer Type to BINARY

    { This is the thing that causes the BUG }
    MyFTP.AutoLogin := False;

    { Connect and Authenticate manually to the server }
    MyFTP.Connect;
    MyFTP.Login;

    { Upload any file }
    MyFTP.Put('c:\myfile','/myfile',False);
    // The file is Sent via ASCII Transfer Type Mode ;(

    MyFTP.Disconnect;

  finally
    MyFTP.Free;
  end;
end;

An Workaround for this is set the AutoLogin to True (so the Login method call isn't necessary too) or including the following lines imediatelly after the call to the "Login" method:

MyFTP.TransferType := ftASCII; // changes the Transfer Type to ASCII
MyFTP.TransferType := ftBinary; // "forces" the Transfer Type to be changed to Binary

>> OR <<

SendCmd('TYPE I', 200); // Send the command direct to the server

Regards,

Diego Queiroz

Replies