繁体   English   中英

Delphi和IdFtp-如何将所有文件上传到目录

[英]Delphi and IdFtp - How to upload all files into directory

我在目录中有几个xml文件,但是我只能按文件发送文件。 我想发送该目录中的所有文件。 我怎样才能做到这一点?

idftp1.Put('C:\MyDir\*.xml','/xml/*.xml');

Indy目前不实现任何形式的多次放置方法(FTP协议本身不具有这种功能)。 您将必须列出给定目录中的所有文件,并分别为每个文件调用Put 例如:

procedure GetFileList(const Folder, Filter: string; FileList: TStrings);
var
  Search: TSearchRec;
begin
  if FindFirst(Folder + Filter, faAnyfile, Search) = 0 then
  try
    FileList.BeginUpdate;
    try
      repeat
        if (Search.Attr and faDirectory <> faDirectory) then
          FileList.Add(Search.Name);
      until
        FindNext(Search) <> 0;
    finally
      FileList.EndUpdate;
    end;
  finally
    FindClose(Search);
  end;
end;

procedure MultiStor(FTP: TIdFTP; const Folder: string; const Filter: string = '*.*');
var
  I: Integer;
  FileList: TStrings;
begin
  FileList := TStringList.Create;
  try
    GetFileList(Folder, Filter, FileList);
    for I := 0 to FileList.Count-1 do
      FTP.Put(Folder + FileList[I]);
  finally
    FileList.Free;
  end;
end;

或类似的最新的Delphi版本:

procedure MultiStor(FTP: TIdFTP; const Folder: string; const Filter: string = '*.*');
var
  FileName: string;
begin
  for FileName in TDirectory.GetFiles(Folder, Filter) do
    FTP.Put(Folder + FileName);
end;

及其调用:

MultiStor(IdFTP1, 'C:\MyFolder\', '*.xml');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM