首页 > 解决方案 > 使用 Delphi XE 从 FTP 服务器下载目录

问题描述

我使用了这个代码,但我有时会收到““xxx.xxx”不理解的错误信息。而且它没有下载,而且我收到“无法建立数据连接:连接超时”消息。

我的 ConnectionTimeOut 设置是 240000。

我能做些什么?你能帮我吗?我正在使用德尔福 XE。

有美好的一天。

标签: delphiftp

解决方案


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

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 文件名。


推荐阅读