我在目录中有几个xml文件,但我只能逐个文件发送.我想发送该目录中的所有文件.我怎样才能做到这一点?
idftp1.Put('C:\MyDir\*.xml','/xml/*.xml');
Run Code Online (Sandbox Code Playgroud)
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;
Run Code Online (Sandbox Code Playgroud)
或者类似于最近的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;
Run Code Online (Sandbox Code Playgroud)
它的电话:
MultiStor(IdFTP1, 'C:\MyFolder\', '*.xml');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2098 次 |
| 最近记录: |