Question

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 ?
Was it helpful?

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');

OTHER TIPS

DO NOT use the OnWork... events to drive your business logic! They are meant for status only. For the most part, Indy is NOT event driven, minus a few exceptions.

In this case, OnWorkEnd triggers after the raw file data has been transmitted but BEFORE the server's response to the upload has been received and processed. The correct way to upload another file is to simply call Put() again after the previous call to Put() exits, eg:

procedure TForm1.UploadFiles;
begin
  try
    IdFTP.Connect;
    try
      while (there is a file to upload) do
      begin
        if (directory is different than current) then
          IdFTP.ChangeDir(directory);
        IdFTP.Put(fileName, ExtractFileName(fileName));
      end;
    finally
      IdFTP.Disconnect;
    end;
  except
    on E: Exception do
      ShowMessage(E.Message);
  end;
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top