Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Работа с сетью в Delphi
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 10.10.2012, 22:44   #1
yassinov
 
Регистрация: 13.09.2010
Сообщений: 6
По умолчанию IDFtp Transfer File/Folder/Subdirectory

Hi

i need some advice because i have some problems with idftp dirs upload !
the current code working but the problem that upload start from subdirectories
only !
Example :
+MainDir
-SubDir1
-SubDir2
-.........
Upload will transfer (SubDir1 & SubDir2,..) but will not creat (MainDir) folder
transfer will be directly for subdirectories !

Код:
procedure UploadFTP;
  procedure GetDir(dir: string);
  var
    SearchRec: TSearchRec;
    details, nodetails: TStringList;
    k: Integer;
  begin

    if FindFirst(dir + '*.*', faAnyFile, SearchRec) = 0 then
    begin
      repeat

        if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
        begin
          //if we found a folder
             if (SearchRec.Attr and faDirectory) = faDirectory then
          begin
            //get folder contents from ftp. one with details, one without
            details   := TStringList.Create;
            nodetails := TStringList.Create;
            Form1.idFTP1.List(details, '', True);
            Form1.idFTP1.List(nodetails, '', False);
            for k := details.Count - 1 downto 0 do
            begin
              if details.Strings[k] <> '' then
              begin
                if (details.Strings[k][1] <> 'd') or
                  (nodetails.Strings[k] = '.') or
                  (nodetails.Strings[k] = '..') then
                begin
                  details.Delete(k);
                  nodetails.Delete(k);
                end;
              end;
            end;
            if nodetails.IndexOf(SearchRec.Name) = -1 then
            begin
              Form1.idFTP1.MakeDir(SearchRec.Name);
            end;

            Form1.idFTP1.ChangeDir(SearchRec.Name);
            details.Free;
            nodetails.Free;
            GetDir(dir + SearchRec.Name + '\');
            Form1.idFTP1.ChangeDirUp;
          end
          else
          begin
            Form1.idFTP1.Put(dir + SearchRec.Name, SearchRec.Name);
          end;
        end;
      until FindNext(SearchRec) <> 0;
      FindClose(SearchRec);
    end;
  end;
var
  dir: string;
  details, nodetails: TStringList;
  k: Integer;
begin
  with Form1.idFTP1 do
  begin
    Host     := Form1.FtpServerEdit.Text;          
    Username := 'root';
    // Adjust your data here
    Password := Form1.PasswordEdit.Text;
    Passive := True;                     
  end;

  //if you want to upload you data to an remote-directory, enter it below (does not matter if 'dir\dir' or 'dir/dir')

  dir := StringReplace('', '\', '/', [rfReplaceAll]);
   if dir <> '' then
  begin
    if dir[1] = '/' then Delete(dir, 1, 1);
   if dir[Length(dir)] <> '/' then dir := dir + '/';
   while Pos('/', dir) > 0 do
    begin
      details   := TStringList.Create;
      nodetails := TStringList.Create;
      Form1.idFTP1.List(details, '', True);
      Form1.idFTP1.List(nodetails, '', False);
      for k := details.Count - 1 downto 0 do
      begin
        if details.Strings[k] <> '' then
        begin
          if (details.Strings[k][1] <> 'd') or
            (nodetails.Strings[k] = '.') or
            (nodetails.Strings[k] = '..') then
          begin
            details.Delete(k);
            nodetails.Delete(k);
          end;
        end;
      end;
      if nodetails.IndexOf(Copy(dir, 1, Pos('/', dir) - 1)) = -1 then
      begin
        Form1.idFTP1.MakeDir(Copy(dir, 1, Pos('/', dir) - 1));
      end;
      Form1.idFTP1.ChangeDir(Copy(dir, 1, Pos('/', dir) - 1));
      Delete(dir, 1, Pos('/', dir));
      details.Free;
      nodetails.Free;
    end;
  end;
 
  dir := Form1.spSkinSelectDirectoryDialog1.Directory;
 if dir[Length(dir)] <> '\' then dir := dir + '\';
  GetDir(dir);
  Form1.idFTP1.Disconnect;
end;
regards , yassinov
yassinov вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
В чём разница между unit, header file, cpp file? TwiX Общие вопросы C/C++ 6 29.04.2012 19:49
Проблема з Folder Lock! amidiys Безопасность, Шифрование 0 18.04.2010 23:16