Solved

idftp uploading in delphi

Posted on 2011-03-17
3
1,378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 …

732 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