Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi和IdFtp-如何将所有文件上载到目录_Delphi_Ftp - Fatal编程技术网

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

Delphi和IdFtp-如何将所有文件上载到目录,delphi,ftp,Delphi,Ftp,我在一个目录中有几个xml文件,但我只能逐个文件发送。我想发送该目录中的所有文件。我该怎么做 idftp1.Put('C:\MyDir\*.xml','/xml/*.xml'); Indy目前没有实现任何类型的多重put方法(FTP协议本身没有这种功能)。您必须列出给定目录中的所有文件,并分别调用每个文件。例如: procedure GetFileList(const Folder, Filter: string; FileList: TStrings); var Search: TSea

我在一个目录中有几个xml文件,但我只能逐个文件发送。我想发送该目录中的所有文件。我该怎么做

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

Indy目前没有实现任何类型的多重put方法(FTP协议本身没有这种功能)。您必须列出给定目录中的所有文件,并分别调用每个文件。例如:

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;
以及它的号召:

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

Indy目前没有实现任何类型的多重put方法(FTP协议本身没有这种功能)。您必须列出给定目录中的所有文件,并分别调用每个文件。例如:

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;
以及它的号召:

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

第二个示例将文件收集到一个列表中,然后迭代该列表。第一个例子也应该这样做,例如使用
TStringList
@Remy,这是为了简单。但是您是对的,这两个任务应该分开(固定)。第二个示例将文件收集到一个列表中,然后迭代该列表。第一个例子也应该这样做,例如使用
TStringList
@Remy,这是为了简单。但你是对的,这两项任务应该分开(固定)。