Search code examples
delphiuploading

Using idFTP to upload files


I'm trying to upload file using the the idFTP component and have defined what I can see as the essential properties as such:

  FTPClient.Host  := tblFtpFTPHost.AsString;
  FTPClient.Username := tblFTPUsername.AsString;
  FTPClient.Password := tblFTPPassword.AsString;
  FTPClient.Port     := tblFTPPort.AsInteger;

However when I run the command -

  FTPClient.Connect;

It will fail with the following error message:

  Project Uploader.exe raised exception class EIdPortRequired with message ''.

Am I not providing the information to the correct properties? Do I need another component on my form to allow me to upload files?

I'm currently using Delphi XE as my IDE.

Thanks.


Solution

  • It seems that your port value is 0. This is the only place where Indy throws this exception:

    procedure TIdTCPClientCustom.Connect;
    begin
      // Do not call Connected here, it will call CheckDisconnect
      if Connected then begin
        EIdAlreadyConnected.Toss(RSAlreadyConnected);
      end;
    
      if Host = '' then begin
        EIdHostRequired.Toss('');
      end;
      if Port = 0 then begin
        EIdPortRequired.Toss('');
      end;
     ...
    

    Please check that the port value is not 0.