从FTP服务器下载目录

从FTP服务器下载目录

本文介绍了从FTP服务器下载目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过RAD Studio(IdFTP)开发FTP客户端.如何从服务器下载目录?Delphi或C ++.谢谢.

I am developing FTP client by RAD Studio (IdFTP). How I can dowload directory from server?Delphi or C++. Thanks.

推荐答案

您需要调用TIdFTP.ChangeDir()转到所需的起始目录,然后调用TIdFTP.List()检索其文件和子目录的名称,然后循环浏览TIdFTP.DirectoryListing在每个文件名上调用TIdFTP.Get()并将每个子目录名称存储到您自己的本地列表中,然后最后在本地列表中的每个子目录上重复上述步骤.

You need to call TIdFTP.ChangeDir() to go to the desired starting directory, then call TIdFTP.List() to retrieve the names of its files and subdirectories, then loop through the TIdFTP.DirectoryListing calling TIdFTP.Get() on each filename and store each subdirectory name into your own local list, then finally repeat the above steps on each subdirectory in your local list.

例如:

Procedure DownloadFolder(ARemoteFolder, ALocalFolder: string);
Var
  SubFolders: TStringList;
  I: Integer;
Begin
  ALocalFolder := IncludeTrailingPathDelimiter(ALocalFolder);
  ForceDirectories(ALocalFolder);
  SubFolders := TStringList.Create;
  Try
    FTP.ChangeDir(ARemoteFolder);
    FTP.List;
    For I := 0 to FTP.DirectoryListing.Count-1 do
    Begin
      If FTP.DirectoryListing[I].ItemType = ditFile then
      Begin
        FTP.Get(FTP.DirectoryListing[I].FileName, ALocalFolder + FTP.DirectoryListing[I].FileName);
      End
      Else if FTP.DirectoryListing[I].ItemType = ditDirectory then
      Begin
        if (FTP.DirectoryListing[I].FileName <> '.') and FTP.DirectoryListing[I].FileName <> '..') then
          SubFolders.Add(FTP.DirectoryListing[I].FileName);
      End;
    End;
    For I := 0 to SubFolders.Count-1 do
    Begin
      DownloadFolder(ARemoteFolder + '/' + SubFolders[I], ALocalFolder + SubFolders[I]);
    End;
  Finally
    SubFolders.Free;
  End;
End;
DownloadFolder('/StartingDir', 'C:\Downloaded');

这篇关于从FTP服务器下载目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 00:06