Indy FTP 客户端在尝试开始另一个上传后出现错误?

发布于 2024-12-15 06:28:57 字数 430 浏览 4 评论 0原文

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;

这是大部分代码。 我希望当第 1 个上传完成后开始另一个上传,但此代码似乎出现错误 10048。

  • 将文件和命令序列上传到服务器的正确方法是吗?
  • 为什么这个错误 10048 不断上升,以及如何修复它?
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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九命猫 2024-12-22 06:28:57

不要使用 OnWork... 事件来驱动您的业务逻辑!它们仅用于地位。在大多数情况下,Indy 不是事件驱动的,除了一些例外。

在这种情况下,OnWorkEnd 在原始文件数据传输后但在服务器对上传的响应已收到并处理之前触发。上传另一个文件的正确方法是在上次调用 Put() 退出后再次调用 Put(),例如:

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;

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;
谎言 2024-12-22 06:28:57

错误 10048 = 套接字已在使用中:信息

您不需要WorkEnd 事件,Put 语句在完成上传文件后返回:

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

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');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文