使用Delphi XE从FTP服务器下载目录

时间:2020-03-06 06:13:05

标签: delphi ftp

我使用了this codes,但有时会收到““ xxx.xxx”无法理解“的错误消息。而且它不会下载,因此我收到“无法建立数据连接:连接超时”消息。

我的ConnectionTimeOut设置为240000。

我该怎么办?你能帮我吗?我正在使用Delphi XE。

祝你有美好的一天。

1 个答案:

答案 0 :(得分:1)

最好包含您自己的代码来解决您的问题。但是,要下载我的文件, 我将文件或文件夹压缩到服务器上,然后在客户端中收到以下代码:

var
  STListZip: TStringList;
  SZipDown: String;
  fFtp:TIdFTP;
begin
  fFtp := TIdFTP.Create(nil);

  fFtp.Passive := true;
  fFtp.Host := 'myserver.com';
  fFtp.Username := 'u1';
  fFtp.Password := '1';
  fFtp.port:='21';
  fFtp.ConnectTimeout := 20000;
  fFtp.TransferTimeout := 20000;
  try
    fFtp.Connect;
    fFtp.ChangeDir('');
  except
    on E: Exception do
    begin
      ShowMessage('ERROR ftp not connect');
      Exit;
    end;
  end;

  if fFtp.Connected then
  begin
    STListZip := TStringList.Create;
    fFtp.List(STListZip, 'abc.zip', false);
    if STListZip.Count < 1 then
    begin
      ShowMessage('ERROR file not exist');
      Exit;
    end;
    STListZip.Sort;
    SZipDown := STListZip[STListZip.Count - 1];
    try
        fftp.BeginWork(wmRead);
        fftp.Get(SZipDown, 'd:\', true, fftp.ResumeSupported);
        fftp.Disconnect();
        fftp.EndWork(wmRead);
    except
        on E: Exception do
        begin
          ShowMessage('ERROR File not download');
          Exit;
        end;
    end;
  end;
end;

注意:代替abc.zip,您可以输入*.zip来获取所有zip文件名。