Search code examples
delphiindyindy10

Indy FTP Client rising error, after trying to start another upload?


IdFTP: TIdFTP;
...
procedure TForm1.IdFTPWorkEnd(ASender: TObject; AWorkMode: TWorkMode);
begin
   IdFTP.Disconnect;

   try

      IdFTP.Connect;

      IdFTP.ChangeDir( directory );
      IdFTP.Put( fileName, ExtractFileName( fileName ) );

   except

   end;

end;

This is most of the code. I wish when the 1 upload complete to start another, but this code seems to rise an error 10048.

  • is it correct way to upload sequence of files and commands to the server ?
  • why this error 10048 is rising, and how to fix it ?

Solution

  • Error 10048 = Socket already in use: info

    You don't need the WorkEnd event, Put statement returns when its finished with uploading a file:

      // loop
      for I := 0 to files.Count-1 do
      begin
        idFtp1.Connect;
        idFtp1.Put(files[i]);
        idFtp1.Disconnect;
      end;
    
      // or
      idFtp1.Put('MyFirstFile');
      idFtp1.DisConnect;
      // ......
      idFtp1.Connect;
      idFtp1.ChangeDir('DirSecondFile');
      idFtp1.Put('MySecondFile');