Solved

idftp uploading in delphi

Posted on 2011-03-17
3
1,349 Views
Last Modified: 2012-06-21
Hello experts.Please help me with one trouble.
i have 2 function :
function CopySubDirStruct(Dir, FTPTargetDir: string): integer;  // Dir & FTPTargetDir Should be teminated with \
var
  sr: TSearchRec;
  n: integer;
begin
  n:= 0;
  if FindFirst(Dir+'*.*', faDirectory, sr) = 0 then
  begin
    repeat
      if ((sr.Attr and faDirectory)=sr.Attr) and (Pos('.', sr.Name)=0) then
     begin
        form3.idftp1.MakeDir(FTPTargetDir+sr.Name);
        n:= n + CopySubDirStruct(Dir+sr.Name+'\', FTPTargetDir+sr.Name+'\');
     end;
    until FindNext(sr) <> 0;
    FindClose(sr);
  end;
  Result:= n;
end;

function CopyDirStruct(Dir, FTPTargetDir: string): integer;  // Dir & FTPTargetDir Should be teminated with \ and /
var
  sr: TSearchRec;
  n: integer;
begin
  n:= 0;
  if FindFirst(Dir+'*.*', faDirectory, sr) = 0 then
  begin
    repeat
      if ((sr.Attr and faDirectory)=sr.Attr) and (Pos('.', sr.Name)=0) then
     begin
        if (FTPTargetDir='') then
          form3.idftp1.ChangeDir('/')
        else form3.idftp1.ChangeDir(FTPTargetDir);
        form3.idftp1.MakeDir(sr.Name);
        n:= n + CopySubDirStruct(Dir+sr.Name+'\', FTPTargetDir+sr.Name+'/');

     end;
    until FindNext(sr) <> 0;
    FindClose(sr);
  end;
  Result:= n;
end;

This working good.This function makes dirs to ftp server from pc folder.
Please help : how i can modify this function that it uploads ALL files from any dir?

Thanks.
0
Comment
Question by:helyonprime96
3 Comments
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 250 total points
ID: 35160723
change that function first so you aren't dependant on form3 anymore
 
function CopyDirStruct(Dir, FTPTargetDir: string; IdFtp: TIdFtp): integer;  // Dir & FTPTargetDir Should be teminated with \ and /
var
  sr: TSearchRec;
  n: integer;
begin
  n:= 0;
  if FindFirst(Dir+'*.*', faDirectory, sr) = 0 then
  begin
    repeat
      if ((sr.Attr and faDirectory)=sr.Attr) and (Pos('.', sr.Name)=0) then
     begin
        if (FTPTargetDir='') then
          idftp.ChangeDir('/')
        else 
          idftp.ChangeDir(FTPTargetDir);
        idftp.MakeDir(sr.Name);
        n:= n + CopySubDirStruct(Dir+sr.Name+'\', FTPTargetDir+sr.Name+'/');

     end;
    until FindNext(sr) <> 0;
    FindClose(sr);
  end;
  Result:= n;
end;

Open in new window


how do you call this func ?
0
 
LVL 24

Assisted Solution

by:jimyX
jimyX earned 250 total points
ID: 35162595
Try this please:
Procedure UploadFiles(Dir, FTPTargetDir: string);
var
  SR : TSearchRec;
begin
  // Dir is the Path of the directory you are searching its files
  if FindFirst(Dir + '*.*', faAnyFile, SR) = 0 then
    begin
      repeat
        if (SR.Attr <> faDirectory) then
          begin
            // the file path can be obtained by using Dir+SR.Name so you can upload it or do whatever you want with it
            form3.idftp1.Put(Dir + SR.Name, FTPTargetDir + SR.Name);
          end;
       until FindNext(SR) <> 0;
      FindClose(SR);
    end;
end;

function CopySubDirStruct(Dir, FTPTargetDir: string): integer;  // Dir & FTPTargetDir Should be teminated with \
var
  sr: TSearchRec;
  n: integer;
begin
  n:= 0;
  if FindFirst(Dir+'*.*', faDirectory, sr) = 0 then
  begin
    repeat
      if ((sr.Attr and faDirectory)=sr.Attr) and (Pos('.', sr.Name)=0) then
     begin
        form3.idftp1.MakeDir(FTPTargetDir+sr.Name);
        UploadFiles(Dir + SR.Name+'\', FTPTargetDir+SR.Name+'\');
        n:= n + CopySubDirStruct(Dir+sr.Name+'\', FTPTargetDir+sr.Name+'\');
     end;
    until FindNext(sr) <> 0;
    FindClose(sr);
  end;
  Result:= n;
end;

function CopyDirStruct(Dir, FTPTargetDir: string): integer;  // Dir & FTPTargetDir Should be teminated with \ and /
var
  sr: TSearchRec;
  n: integer;
begin
  n:= 0;
  if FindFirst(Dir+'*.*', faDirectory, sr) = 0 then
  begin
    repeat
      if ((sr.Attr and faDirectory)=sr.Attr) and (Pos('.', sr.Name)=0) then
     begin
        if (FTPTargetDir='') then
          form3.idftp1.ChangeDir('/')
        else form3.idftp1.ChangeDir(FTPTargetDir);
        form3.idftp1.MakeDir(sr.Name);
        n:= n + CopySubDirStruct(Dir+sr.Name+'\', FTPTargetDir+sr.Name+'/');

     end;
    until FindNext(sr) <> 0;
    FindClose(sr);
  end;
  Result:= n;
end;

Open in new window

Consider what Geert said.
0
 

Author Closing Comment

by:helyonprime96
ID: 35168630
thanks experts.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an explanation of a simple data model to help parse a JSON feed
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question