从远程FTP下载文件列表

从远程FTP下载文件列表

本文介绍了从远程FTP下载文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用TidFTP组件时遇到问题。

I'm getting a problem using the TidFTP component.

我可以使用类似这样的代码与服务器连接

I'm able to connect with the server using a code like this

vFileList := TStringList.Create;
oClientFTP := TidFTP.Create(nil);
oClientFTP.Port := PortFTP;
oClientFTP.Host := IPHost;
oClientFTP.UserName := UserFTP;
oClientFTP.Password := PasswordFTP;

从StringList中获取多个文件(该元素正好有778个元素)后,元素号为no。检索到137,异常EIdAcceptTimeout引发为 Accept timed out。消息。

After getting several files from the StringList (this one has exactly 778 elements) when the element no. 137 is retrieved the exception EIdAcceptTimeout is raised with "Accept timed out." message.

我运行的代码是这样的(顺便在线程中运行)

The code that I run is like this (runs in a Thread by the way)

procedure TDownloadFTP.Get;
begin
try
  for I := 0 to vFileList .Count - 1 do
  begin
    sFileName:= vFileList [I];
    posPoint := LastDelimiter('.', sFileName);
    if posPoint = 0 then
      ForceDirectories(ExtractFilePath(Application.ExeName) + '/BackUp/' + sFileName)
    else
      try
        oClienteFTP.Get(sFileName,IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName) + '/BackUp/') + sFileName, True);
    except

      on E: EIdReplyRFCError do
      begin
      end;
      on E: Exception do
        exceptionList.Add(sFileName);
  end;
end;

例外后,文件已正确下载,但该过程每个文件大约需要25秒(我m下载2KB png图像)。

After the exception, the file is downloaded correctly but the process needs like 25 seconds per file (I'm downloading 2KB png images).

是否知道此异常的含义?

Any idea of the meaning of this Exception?

谢谢

推荐答案

EIdAcceptTimeout 上进行搜索将导致在Indy论坛中进行以下讨论:

Googling for EIdAcceptTimeout leads to this discussion in the Indy forum:

Remy Lebeau指出:

Where Remy Lebeau states:

因此,解决方案可能是为您添加一行

So, the solution could be for you to add a line

oClientFTP.Passive := True;

Btw。在代码段中,您同时拥有oClientFTP和oClienteFTP。如有需要,请调整我的建议。

Btw. In your code snippets you have both oClientFTP and oClienteFTP. Adjust my suggestion if needed.

这篇关于从远程FTP下载文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 07:06