Solved

idftp uploading in delphi

Posted on 2011-03-17
3
1,318 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 36

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This is an explanation of a simple data model to help parse a JSON feed
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now