簡體   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