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

使用Delphi XE从FTP服务器下载目录,delphi,ftp,Delphi,Ftp,我用过,但有时会出现“xxx.xxx”不明白的错误消息。它没有下载,我收到了“无法建立数据连接:连接超时”的消息 我的连接时间设置为240000 我能做什么?你能帮我吗?我正在使用DelphiXE 祝您今天愉快。最好包含您自己的代码来解决您的问题。但是,要下载我的文件, 我在服务器上压缩文件或文件夹,然后在客户端接收以下代码: var STListZip: TStringList; SZipDown: String; fFtp:TIdFTP; begin fFtp := TIdF

我用过,但有时会出现“xxx.xxx”不明白的错误消息。它没有下载,我收到了“无法建立数据连接:连接超时”的消息

我的连接时间设置为240000

我能做什么?你能帮我吗?我正在使用DelphiXE


祝您今天愉快。

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

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;
var
STListZip:TStringList;
SZipDown:字符串;
福州保税港区:TIdFTP;
开始
fFtp:=TIdFTP.Create(无);
福州保税港区被动式:=真;
主机:='myserver.com';
福州保税港区用户名:='u1';
福州保税港区密码:='1';
福州保税港区:='21';
fFtp.ConnectTimeout:=20000;
fFtp.TransferTimeout:=20000;
尝试
福州保税港区连接;
fFtp.ChangeDir(“”);
除了
关于E:Exception-do
开始
ShowMessage('ERROR ftp not connect');
出口
结束;
结束;
如果福州保税港区已连接,则
开始
STListZip:=TStringList.Create;
福州保税港区清单(STListZip,'abc.zip',假);
如果STListZip.Count小于1,则
开始
ShowMessage('错误文件不存在');
出口
结束;
STListZip.Sort;
SZipDown:=STListZip[STListZip.Count-1];
尝试
福州保税港区开始工作(wmRead);
Get(SZipDown,'d:\',true,支持fftp.resume);
fftp.Disconnect();
福州保税港区尾工(wmRead);
除了
关于E:Exception-do
开始
ShowMessage('错误文件未下载');
出口
结束;
结束;
结束;
结束;

注意:您可以放置
*.zip
来获取所有zip文件名,而不是
abc.zip

您引用的代码不包括实例化
ftp
或设置连接。请在代码未连接时显示该代码。